n.e*_*ind 2 iphone animation cocoa-touch objective-c
我想知道实现一系列不同动画的最佳方法是什么.例如,如果我调用以下方法并尝试向右,向左和向上设置相同对象的动画,它将无法工作,因为编译器不以线性方式处理它们,而我最终得到了我的对象只是上去(跳过左右两步):
-(IBAction)clickStart
{
[self Animation1];
[self Animation2];
[self Animation3];
}
Run Code Online (Sandbox Code Playgroud)
现在我可以做到这一点,但它对我来说感觉很麻烦和怪异.考虑这是Animation1的方法:
[pageShadowView setFrame:CGRectMake(100, 0, CGRectGetWidth(pageShadowView.frame), CGRectGetHeight(pageShadowView.frame))];
[UIView beginAnimations:@"Animation1" context:nil]; // Begin animation
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(Animation2)];
[pageShadowView setFrame:CGRectMake(200, 0, CGRectGetWidth(pageShadowView.frame), CGRectGetHeight(pageShadowView.frame))];
[UIView commitAnimations]; // End animations
Run Code Online (Sandbox Code Playgroud)
然后我可以在Animation2中做同样的事情,即一旦完成就调用Animation3.但说实话,这是非常令人困惑的,而不是一个非常清晰的编码方法.反正有没有像我在开头建议的那样获得一个更"线性"的代码(这不起作用),或者我只需要使用选择器方法?
谢谢你的任何建议!
mxc*_*xcl 10
如果您不必支持iOS <4:
[UIView animateWithDuration:0.2 animations:^{
// animation 1
} completion:^(BOOL finished){
[UIView animateWithDuration:0.2 animations:^{
// animation 2
} completion^(BOOL finished){
[UIView animateWithDuration:0.2 animations:^{
// animation 3
}];
}];
}]
Run Code Online (Sandbox Code Playgroud)