【发布时间】:2012-01-01 16:13:33
【问题描述】:
假设基于块的动画链如下:
UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
//animation 1
[UIView animateWithDuration:2 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
view.frame = CGRectMake(0, 100, 200, 200);
} completion:^(BOOL finished){
//animation 2
[UIView animateWithDuration:2 delay:0 options: UIViewAnimationOptionRepeat |UIViewAnimationOptionAutoreverse animations:^{
[UIView setAnimationRepeatCount:1.5];
view.frame = CGRectMake(50, 100, 200, 200);
} completion:^(BOOL finished){
//animation 3
[UIView animateWithDuration:2 delay:0 options:0 animations:^{
view.frame = CGRectMake(50, 0, 200, 200);
} completion:nil];
}];
}];
停止这种动画的最佳方法是什么?只是打电话
[view.layer removeAllAnimations];
还不够,因为这只会停止当前正在执行的动画块,其余的将按顺序执行。
【问题讨论】:
-
编译器允许吗?我在嵌套这么深的块时遇到了麻烦。 (现在不记得是 gcc 还是 clang 了——更可能的是,clang 允许更深入,但仍然不是很多。)
-
iOS 4 及更高版本支持基于块的动画。嵌套效果很好。
-
那么要么编译器错误得到修复,你正在使用clang,要么你没有达到限制。
标签: iphone objective-c ios ipad ios4