2010-05-11 113 views
5

我想在iPhone上对视图应用3D旋转(特别是对UILabel)。什么是最简单的方法来做到这一点?将3D旋转应用到iPhone视图

代码示例将不胜感激。

+0

这个问题是非常类似于你:HTTP ://stackoverflow.com/questions/347721/ uiview-perspective-transform – 2010-05-11 17:38:43

+0

感谢Brad。你认为我应该删除这个吗? – hpique 2010-05-11 18:00:07

回答

11

对于2D旋转用途:

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

对于3D变换看到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示例

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

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