簡體   English   中英

iOS 6.1動畫不起作用

[英]iOS 6.1 animation not working

我為動畫創建的以下方法:

-(void)shakingAnimationForGate:(UIImageView *)image leftShaking:(CGAffineTransform)leftTransform rightShaking:(CGAffineTransform)rightTransform animationName:(NSString *)string{

    [UIView animateWithDuration:5.0
                          delay:0.5
                        options: UIViewAnimationOptionCurveEaseOut
                     animations:^{

    image.transform = leftTransform;  // starting point

    [UIView beginAnimations:string context:(__bridge void *)(image)];
    [UIView setAnimationRepeatAutoreverses:YES]; // important
    [UIView setAnimationRepeatCount:20];
    [UIView setAnimationDelay:0.1];
    [UIView setAnimationDuration:0.06];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(shakeEnded:finished:context:)];

    image.transform = rightTransform; // end here & auto-reverse

    [UIView commitAnimations];

    }
        completion:^(BOOL finished){
            NSLog(@"end of shaking");
    }];

}

這使得UIView可以“搖晃”。

然后我正在使用這種方法:

CGAffineTransform leftShake = CGAffineTransformMakeTranslation(-2, 6);
CGAffineTransform rightShake = CGAffineTransformMakeTranslation(0, 3);

[self shakingAnimationForGate:imageLeft leftShaking:leftShake rightShaking:rightShake animationName:@"left view shake"];

其中imageLeftUIImageView

所以我的問題是,這種方法無法在iOS 6.1上播放動畫。 雖然在iOS 7上運行良好。 有什么問題嗎?

編譯時,Xcode會稍微優化您的代碼。 例如,如果執行以下代碼,則僅執行最后一行:

[self.view setBackgroundColor:[UIColor greenColor]];
[self.view setBackgroundColor:[UIColor yellowColor]];

動畫也很可能也是這種情況。

將還原部分移動到完成部分。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM