【发布时间】:2011-02-18 03:11:58
【问题描述】:
我想在 iPhone 中的视图(尤其是 UILabel)上应用 3D 旋转。最简单的方法是什么?
非常感谢您提供代码示例。
【问题讨论】:
-
谢谢布拉德。你认为我应该删除这个吗?
我想在 iPhone 中的视图(尤其是 UILabel)上应用 3D 旋转。最简单的方法是什么?
非常感谢您提供代码示例。
【问题讨论】:
对于 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);
【讨论】:
// 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];
【讨论】:
Swft 3 示例
let rotationTransform = CATransform3DRotate(myView.layer.transform, CGFloat.pi, 1, 0, 0)
UIView.animate(withDuration: 0.5) {
self.myView.layer.transform = rotationTransform
}
【讨论】: