入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

如何停止UIView的animation

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

使用动画通常有两种方法: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
}
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
  • 上一篇:没有了
  • 下一篇:没有了
未上传头像