繁体   English   中英

旋转动画在iOS 7中不起作用

[英]Rotation animation is not working in iOS 7

我想旋转UIImageView ,它可以在iOS8中使用,但不能在iOS7中使用。 这是代码,我在做,

- (void)awakeFromNib {
    [self createAnimation];
}



- (void)animationStart {
    [self.animationImageView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}



- (void)animationStop {
    [self.animationImageView.layer removeAnimationForKey:@"rotationAnimation"];
}



- (void)createAnimation {
    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    rotationAnimation.toValue = [NSNumber numberWithFloat: -M_PI * 2.0 ];
    rotationAnimation.duration = 0.7;
    rotationAnimation.cumulative = YES;
    rotationAnimation.repeatCount = CGFLOAT_MAX;
}  

使用此代码来旋转图像

- (void)startSpinImage
{
    if ([_img.layer animationForKey:@"SpinAnimation"] == nil)
    {
        CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
        animation.fromValue = [NSNumber numberWithFloat:0.0f];
        animation.toValue = [NSNumber numberWithFloat: 2*M_PI];
        animation.duration = 10.0f;
        animation.repeatCount = INFINITY;
        [_img.layer addAnimation:animation forKey:@"SpinAnimation"];
    }
}

- (void)stopSpinImage
{
    [_img.layer removeAnimationForKey:@"SpinAnimation"];
}

尝试使用

[animationImageView startAnimating];
[animationImageView stopAnimating];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM