将3D旋转应用于iPhone视图

7

我想在iPhone上对一个视图(尤其是UILabel)应用3D旋转。如何最简单地实现这个功能?

提供代码示例将非常感激。


这个问题与你的非常相似:https://dev59.com/ynRC5IYBdhLWcg3wSu97 - Brad Larson
谢谢Brad。你认为我应该删除这个吗? - hpique
3个回答

13

对于2D旋转,请使用以下方法:

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

有关3D变换,请参见该帖子

CATransform3D _3Dt = CATransform3DMakeRotation(radians(90.0f), 1.0, 0.0, 0.0);

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

Swift 3 示例

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

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接