简体   繁体   中英

iOS 6.1 animation not working

The following method that i created for animation:

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

}

which makes UIView do the "shaking".

Then i'm using this method:

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

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

where imageLeft is UIImageView .

So my problem is that this method don't do animation of shaking on iOS 6.1. It's working fine on iOS 7 though. Any ideas what's the problem?

When compiling, Xcode optimises your code a little. For example if you execute the following code, only the last line is executed:

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

Most likely that's the case with the animation as well.

Move the revert part to the completion part.

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