2013-06-25 4 views
2

J'ai créé une carte de visite qui a vue de face & vue arrière. Lorsque je tape sur la vue de face, il faut retourner l'UIView & pour voir le verso de la vue.Renverser deux UIView en utilisant CATransform3D

est ici Code que je suis en train:

CATransform3D transform = CATransform3DMakeRotation(M_PI, 0, 1, 0); 
transform.m34 = 1.0/700.0; 


CABasicAnimation *rotation = [CABasicAnimation animationWithKeyPath:@"transform"]; 
rotation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity]; 
rotation.toValue = [NSValue valueWithCATransform3D:transform]; 
rotation.duration = DURATION; 

CABasicAnimation *translation = [CABasicAnimation animationWithKeyPath:@"position"]; 
translation.fromValue = [NSValue valueWithCGPoint:CGPointMake(self.imageview.center.x,[[self.imageview superview] center].y-45)]; 
translation.toValue = [NSValue valueWithCGPoint:CGPointMake(_frame.origin.x+_frame.size.width/2, 
                  _frame.origin.y+_frame.size.height/2)]; 
translation.duration = DURATION; 


CABasicAnimation *translation = [CABasicAnimation animationWithKeyPath:@"position"]; 
translation.fromValue = [NSValue valueWithCGPoint:CGPointMake(self.imageview.center.x,[[self.imageview superview] center].y-45)]; 
translation.toValue = [NSValue valueWithCGPoint:CGPointMake(_frame.origin.x+_frame.size.width/2, 
                  _frame.origin.y+_frame.size.height/2)]; 
translation.duration = DURATION; 
CAAnimationGroup *group = [CAAnimationGroup animation]; 

group.animations = @[ translation, rotation ]; 
group.duration = DURATION; 
group.delegate = self; 
group.fillMode = kCAFillModeForwards; 
group.removedOnCompletion = NO; 
[layer addAnimation:group forKey:nil]; 

code ci-dessus fonctionne parfaitement pour une vue unique. Comment combiner la deuxième vue pour obtenir l'effet de recul &.

enter image description here

+1

En ce qui concerne '_frame.origin.x + _frame.size.width/2': pourquoi ne pas utiliser' CGRectGetMidX (_frame) '? –

Répondre

3

Utilisation de Core Animation

Vous pouvez ajouter à la fois avant et arrière à une vue du conteneur. La vue arrière aura une rotation de 180 degrés autour de Y et l'avant sera juste normal. Les deux couches seront un seul côté (en mettant layer.doubleSided = NO;.

Ensuite, lorsque vous appliquez la rotation que vous animer la rotation de la vue du conteneur afin que les deux faces avant et arrière animent en même temps.

UIView transitions

ou vous pouvez simplement utiliser le construit dans l'animation flip

transitionFromView:toView:duration:options:completion: 

et passer soit UIViewAnimationOptionTransitionFlipFromLeft ou UIViewAnimationOptionTransitionFlipFromRight pour l'option.

+1

Ronnqvist Merci de m'avoir donné un indice. La méthode layer.doublesided m'a beaucoup aidé. – Anand