0

我为动画创建的以下方法:

-(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 上运行良好。有什么想法有什么问题吗?

4

1 回答 1

0

编译时,Xcode 会稍微优化您的代码。例如,如果您执行以下代码,则仅执行最后一行:

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

很可能动画也是如此。

将还原部分移动到完成部分。

于 2013-10-08T15:32:23.923 回答