2010-04-15 3 views
4

J'utilise un bloc d'animation standard pour basculer sur d'une vue à l'autre, comme celui-ci:assombrissement UIView tout en feuilletant sur l'utilisation UIViewAnimationTransitionFlipFromRight

[UIView beginAnimations:@"FlipAnimation" context:self]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:NO]; 
[UIView setAnimationBeginsFromCurrentState:NO]; 
[containerView exchangeSubviewAtIndex:1 withSubviewAtIndex:0]; 
[UIView commitAnimations]; 

Pendant le cours de l'animation, le « de » vue obscurcit comme commence à se retourner. Comme j'utilise des vues presque identiques des deux côtés qui ne couvrent pas toute la vue (c'est censé représenter une carte physique retournée), cela semble absolument horrible. L'utilisation de [UIColor clearColor] en tant que propriété backgroundColor pour chaque UIView associé n'a pas aidé car les zones transparentes semblaient s'assombrir également.

Des idées sur comment je pourrais me débarrasser de cet effet assombrissant?

Répondre

6

Apparaît que vous devez faire l'animation 'à la main', en utilisant des transformations Core Animation. J'ai divisé l'animation en deux parties. Je tourne d'abord 'viewOne' à mi-chemin avec animation et 'viewTwo' à mi-chemin dans l'autre sens sans animation. Lorsque la première moitié de l'animation est terminée, je fais le reste dans la méthode déléguée. Vos paramètres peuvent varier :)

L'inclinaison est une gracieuseté d'une autre réponse de StackOverflow que j'ai trouvée.

- (IBAction)flip:(id)sender 
{ 
    UIView* viewOne = [self.view.subviews objectAtIndex:0]; 
    UIView* viewTwo = [self.view.subviews objectAtIndex:1]; 

    viewOne.hidden = YES; 

    CATransform3D matrix = CATransform3DMakeRotation (M_PI/2, 0.0, 1.0, 0.0); 
    CATransform3D matrix2 = CATransform3DMakeRotation (-M_PI/2 , 0.0, 1.0, 0.0); 
    matrix = CATransform3DScale (matrix, 1.0, 0.975, 1.0); 
    matrix.m34 = 1.0/-500; 

    matrix2 = CATransform3DScale (matrix2, 1.0, 0.975, 1.0); 
    matrix2.m34 = 1.0/-500; 

    viewOne.layer.transform = matrix2; 

    [UIView beginAnimations:@"FlipAnimation1" context:self]; 
    [UIView setAnimationDuration:1]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(animationPartOneDone)]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; 

    viewTwo.layer.transform = matrix; 

    [UIView commitAnimations];  
} 

-(void)animationPartOneDone 
{ 
    UIView* viewOne = [self.view.subviews objectAtIndex:0]; 
    UIView* viewTwo = [self.view.subviews objectAtIndex:1]; 


    viewOne.hidden = NO; 
    viewTwo.hidden = YES; 

    CATransform3D matrix = CATransform3DMakeRotation (2 * M_PI, 0.0, 1.0, 0.0); 

    matrix = CATransform3DScale (matrix, 1.0, 1.0, 1.0); 

    [UIView beginAnimations:@"FlipAnimation2" context:self]; 
    [UIView setAnimationDuration:1]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; 

    viewOne.layer.transform = matrix; 

    [UIView commitAnimations];  

    [self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0]; 

}