簡體   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