iphone - 在第一次结束动画后触发其他动画(Objective-C)

标签 iphone objective-c core-animation

我有一个简单的动画,它只是修改按钮的位置:

[UIView beginAnimation:nil context:nil];
[UIView setAnimationsDuration:3.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
mybutton.frame = CGREctMake(20, 233, 280, 46);
[UIView commitAnimations];

我想在完成此动画后执行一些其他动画,该怎么做?

最佳答案

你可以看看setAnimationBeginsFromCurrentState: .所有动画都在自己的线程中运行,因此 [UIView commitAnimations] 是一个非阻塞调用。因此,如果您在提交第一个动画后立即开始另一个动画,在适本地设置它是否从当前状态开始之后,我想您会得到您想要的行为。即:

[UIView beginAnimation:nil context:nil];
// set up the first animation
[UIView commitAnimations];

[UIView beginAnimation:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:NO];
// set up the second animation
[UIView commitAnimations];

或者,您可以通过执行以下操作来提供回调

[UIView beginAnimation:nil context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)
// set up the first animation
[UIView commitAnimations];

//...

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
    // set up the second animation here
}

关于iphone - 在第一次结束动画后触发其他动画(Objective-C),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2710939/

相关文章:

iphone - FB登录策略,坚持什么?

iOS:旋转图像,但不旋转 mask 。怎么做这个?

objective-c - CATextLayer + NSAttributtedString + CTParagraphStyleRef

ios - 如何让 CoreAnimation 在动画过程中不忽略异常?

没有提前获取用户详细信息的 iPhone 临时分发

iphone - 防止在从磁盘加载的 UIWebView 中缓存 .css 文件

iOS:使用 "malloc"自动释放分配的内存?

ios - 使用 Core Graphics 时为 "Potential leak of an object"

iphone - 应用内购买不适用于 3G 设备

ios - 如何按降序对日期数组进行排序