比如一个按钮,在做放大缩小或者位移动画时无法响应点击事件 。设置对应的options 即可使他响应点击事件 。
- (void)scaleAnimation:(UIView *)view {
if (动画结束条件) return;
[UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
view.transform = CGAffineTransformScale(view.transform, 1.05, 1.05);
} completion:^(BOOL finished) {
[UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionCurveEaseInOut animations:^{
view.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished) {
[self scaleAnimation:view];
}];
}];
}
指定options: UIViewAnimationOptionAllowUserInteraction 即可在视图做动画的同时可以响应点击事件 。options 是逻辑或的关系可以指定多种options ,中间用 | 隔开 。
注意:用这种循环的方式做动画的话,一定要指定动画结束的条件,否则会产生循环引用导致view 一直无法释放掉 。