objective-c - 多个 UIView 动画

标签 objective-c ios core-animation uiviewanimation

我正在尝试一个接一个地执行多个 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/

相关文章:

objective-c - 带有 inputView 的 UITextField 在某些 iOS 8 模拟器中不起作用

ios - 图像是由 UIImagePickerControllerSourceTypeCamera 拍摄的如何将其保存在 ios 的数据库中

iphone - 如何为 CAShapeLayer 路径和 fillColor 设置动画

ios - 可重定位的 dylib(例如嵌入式框架)仅在 iOS 8.0 及更高版本上受支持(@rpath/libswift_stdlib_core.dylib)

iphone - 重置内容插入后如何设置滚动偏移?

iphone - 正确分配/取消分配 UINavigationControllerDelagate

ios - Facebook iOS SDK 3.1 请求读取和发布权限

ios - 红框移动到核心动画中 UIImage View 的位置

iphone - 理解 CGPathAddArc 时遇到问题

ios - CAAction 的 runActionForKey :object:arguments: arguments take? 可以取什么值