简体   繁体   中英

Rotation animation is not working in iOS 7

I want to rotate an UIImageView , it works in iOS8 but not in iOS7. Here's the code, I'm doing,

- (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;
}  

use this code to image rotate,

- (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"];
}

Try using

[animationImageView startAnimating];
[animationImageView stopAnimating];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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