将3D旋转应用于iPhone视图

时间:2010-05-11 12:32:11

标签: iphone uiview 3d rotation

我想在iPhone中对视图(尤其是UILabel)应用3D旋转。最简单的方法是什么?

非常感谢代码示例。

3 个答案:

答案 0 :(得分:12)

对于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);

答案 1 :(得分:9)

// 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];

答案 2 :(得分:0)

Swft 3示例

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

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