我正在尝试一个接一个地执行多个 UIView 动画。但是,我听说一个接一个地执行多个 UIView 动画是不好的做法,我应该改用 Core Animation。我试过这段代码:
//First Animation
[UIView beginAnimations:@"animation1" context:nil];
[UIView setAnimationDuration:2];
nwView.backgroundColor = [UIColor redColor];
nwView.frame = CGRectMake(CGRectGetMidX(screenSize),
CGRectGetMinY(screenSize),
width,
height);
nwView.transform = CGAffineTransformMakeRotation(45.0f);
[UIView commitAnimations];
//Second Animation
[UIView beginAnimations:@"second animation" context:nil];
[UIView setAnimationDuration:2];
nwView.transform = CGAffineTransformMakeScale(0.5, 0.33);
nwView.backgroundColor = [UIColor purpleColor];
[UIView commitAnimations];
但它只做第二个动画。我知道这个问题类似于 UIView two animations coexisting , 但它的上下文略有不同。
最佳答案
我认为使用 UIView block 连续制作 2 个动画没有任何问题。只需确保在第一个动画的 completino block 中开始第二个动画即可。
如果没有 block (您的示例),它就无法工作,因为您必须为动画设置委托(delegate)或为 setAnimationDidStopSelector 设置选择器。在那里你应该开始第二个动画。
但同样,用 block 做动画没有错(这是首选方式)。
关于objective-c - 多个 UIView 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10792026/