我想在iPhone中对视图(尤其是UILabel)应用3D旋转。最简单的方法是什么?
非常感谢代码示例。
答案 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
}