首次结束动画后触发其他动画(Objective-C)

lud*_*udo 3 iphone core-animation objective-c

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

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

当这个完成时,我想要执行一些其他动画,怎么做?

Set*_*h P 5

你可以看看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];
Run Code Online (Sandbox Code Playgroud)

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

[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
}
Run Code Online (Sandbox Code Playgroud)