2010-05-11 4 views
5

Je voudrais appliquer une rotation 3D sur une vue (en particulier à un UILabel) dans l'iPhone. Quelle est la manière la plus simple de faire ceci?Appliquer la rotation 3D à l'affichage iPhone

Un exemple de code sera très apprécié.

+0

Cette question est très semblable à la vôtre: http : //stackoverflow.com/questions/347721/ uiview-perspective-transformer –

+0

Merci Brad. Pensez-vous que je devrais supprimer celui-ci? – hpique

Répondre

11

Pour une utilisation de rotation 2D:

//rotate label in 45 degrees 
label.transform = CGAffineTransformMakeRotation(M_PI/4); 

Pour les transformations 3D voir this thread:

CATransform3D _3Dt = CATransform3DMakeRotation(radians(90.0f), 1.0, 0.0, 0.0); 
8
// flipping view along axis 
// this will rotate view in 3D along any axis 

[UIView beginAnimations:nil context:nil]; 
CATransform3D _3Dt = CATransform3DRotate(self.layer.transform, 3.14, 1.0, 0.0,0.0); 
[UIView setAnimationRepeatCount:100]; 
[UIView setAnimationDuration:0.08]; 
self.layer.transform=_3Dt; 
[UIView commitAnimations]; 
0

SWFT 3 exemple

let rotationTransform = CATransform3DRotate(myView.layer.transform, CGFloat.pi, 1, 0, 0) 

UIView.animate(withDuration: 0.5) { 
    self.myView.layer.transform = rotationTransform 
}