使用动画通常有两种方法:CAAnimation 和 UIView的animation
两者的主要区别在于:当你想控制或停止某一动画的时候,那么只能用CAAnimation
- 如何停止UIView的animation呢?
/*成员变量*/
UIImageView * _recordImageView; //旋转的图片
__block CGFloat _angle; //记录旋转角度
/*动画代码*/
- (void)startAnimation{
CGAffineTransform endAngle = CGAffineTransformMakeRotation(_angle * (M_PI / 180.0f));
[UIView animateWithDuration:0.1 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
_recordImageView.transform = endAngle;
} completion:^(BOOL finished) {
*if (finished) {*//必须写上,@selector(endAnimation)中的方法才有用
_angle += 5;
[self startAnimation];
}
}];
}
- (void)endAnimation{
[_recordImageView.layer removeAllAnimations];//会结束动画,使finished变量返回Null
}