2010-05-11 4 views
5

Ich möchte eine 3D-Rotation auf eine Ansicht (insbesondere auf ein UILabel) im iPhone anwenden. Was ist der einfachste Weg dies zu tun?3D-Drehung auf iPhone-Ansicht anwenden

Ein Codebeispiel wird sehr geschätzt.

+0

Diese Frage ist zu Ihnen sehr ähnlich: http : //stackoverflow.com/questions/347721/ uiview-perspective-transform –

+0

Danke Brad. Denkst du, ich sollte das löschen? – hpique

Antwort

11

Für 2D-Rotation Verwendung:

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

Für 3D-Transformationen siehe 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 Beispiel

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

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