UIView使用子视图开始动画

Joh*_*ane 9 iphone core-animation

我为视图提供了一个简单易用的"缩放"动画,它以点开头并动画到全屏大小:

        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationBeginsFromCurrentState:YES];
        [UIView setAnimationDuration:1.0];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        myView.frame = CGRectMake(0,0,320,480);
        myView.transform = CGAffineTransformIdentity;  
        [UIView commitAnimations];

到现在为止还挺好 :-)

问题是当我向myView添加子视图时,令我惊讶的是,他们没有遵循他们的superview的动画方案!?!?

顺便说一句.子视图目前在MyView的initWithFrame中照常添加.我试图将他们的转换属性设置为CGAffineTransformIdentity,但它没有帮助.

那么,需要做些什么才能让myView的子视图与其超级视图一起以漂亮的"缩放"方式制作动画?

提前致谢!
/约翰

Jam*_*rke 15

我刚刚遇到了同样的问题,解决方案非常简单.修改帧大小仅影响当前视图,而不影响子视图(如您所注意到的),transform属性也适用于子视图.

我正在尝试与您正在做的事情相反(在显示时有一个子视图显示为"放置"到现有视图的顶部,而不是从中心缩放).这段代码适合我:

self.transform = CGAffineTransformMakeScale(2,2);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.25];
self.transform = CGAffineTransformMakeScale(1,1);
self.alpha = 1.0;
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)

尝试在开始动画之前将self.transform设置为CGAffineTransformMakeScale(0,0),并在提交之前将其设置回(1,1).根本不要修改框架 - 在动画完成后将其保留为视图所需的大小.