2013-10-08 28 views
0

,我为动画创建以下方法:的iOS 6.1的动画不能正常工作

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

其中imageLeft的UIImageView

所以我的问题是,这种方法不会在iOS 6.1上做抖动动画。但它在iOS 7上运行良好。任何想法是什么问题?

+0

只是做[UIView动画]? –

+0

你的意思是commitAnimations?它已经在我创建的方法 – ignotusverum

+0

我假设你正在尝试做一个动画发生20次?哪个开始点A,动画到B点,然后从点A开始全部? –

回答

0

编译时,Xcode会优化你的代码。例如,如果你执行下面的代码,只有最后一行执行:

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

最有可能是与动画的情况下也是如此。

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

+0

谢谢,但我的动画方法在iOS 7上工作,并且“优化”代码没有问题。 – ignotusverum