2010-09-17 7 views
13

hatte ich dieses Stück Code im meinem App:iOS 4.2: Flip Bild mit Block Animationen

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:1]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:imgView cache:YES]; 
    imgView.image = img2; 
[UIView commitAnimations]; 

Aber Verwendung dieses Verfahrens wird in iOS 4.0 und später entmutigt, und ich soll transitionWithView:duration:options:animations:completion:

verwenden Ich kann nicht richtig funktionieren. Kann mir jemand helfen? Thx!

Antwort

19
[UIView transitionWithView:imgView // use the forView: argument 
        duration:1   // use the setAnimationDuration: argument 
        options:UIViewAnimationOptionTransitionFlipFromLeft 
          // check UIViewAnimationOptions for what options you can use 
       animations:^{   // put the animation block here 
           imgView.image = img2; 
          } 
       completion:NULL];  // nothing to do after animation ends. 
+0

Vielen Dank! Klappt wunderbar. – FransGuelinckx

+0

@KennyTM: können Sie mit [NULL vs Nil für Blöcke] klären (http://stackoverflow.com/questions/5766208/which-is-the-right-one-nil-or-null-to-mark-) No-Ziel-C-Block)? – penfold

+6

@FransGuelinckx bitte markieren Sie diese Antwort als akzeptiert, wenn es Ihr Problem gelöst hat. –

3

Ich habe diese Funktion basierend auf dem Code:

- (void)flipCurrentView:(UIView*)oldView withNewView:(UIView*)newView reverse:(BOOL)reverse 
{ 
    newView.alpha = 0; 
    [UIView transitionWithView:newView 
         duration:1  
         options:UIViewAnimationOptionTransitionFlipFromLeft 
        animations:^{   
         oldView.alpha = 0; 
         newView.alpha = 1; 
        } 
        completion:^(BOOL finished){ 
         if(reverse){ 
          [self flipCurrentView:newView withNewView:oldView reverse:NO]; 
         } 
         finished = YES; 
        }]; 
}