2010-09-17 7 views
13

tenía esta pieza de código im mi aplicación:iOS 4.2: giro de imagen utilizando animaciones bloque

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

embargo, el uso de este método no se recomienda en iOS 4.0 y posterior, y yo debería usar transitionWithView:duration:options:animations:completion:

No puedo hacer que esto funcione correctamente. ¿Alguien puede ayudarme? ¡Thx!

Respuesta

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

Muchas gracias! Funciona de maravilla. – FransGuelinckx

+0

@KennyTM: ¿puede aclarar usando [NULL vs nil para bloques] (http://stackoverflow.com/questions/5766208/which-is-the-right-one-nil-or-null-to-mark- no-objetivo-c-bloque)? – penfold

+6

@FransGuelinckx marque esta respuesta como aceptada si resolvió su problema. –

3

Hice esta función en base a su código:

- (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; 
        }]; 
} 
Cuestiones relacionadas