牛骨文教育服务平台(让学习变的简单)
博文笔记

如何停止UIView的animation

创建时间:2015-03-09 投稿人: 浏览次数:6478

使用动画通常有两种方法: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
}
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。