我正在尝试了解如何像这样为我的 UIView
创建深度感知:
我试过这段代码:
var rotationWithPerspective = CATransform3DIdentity;
rotationWithPerspective.m34 = -1.0/500.0/2/2
rotationWithPerspective = CATransform3DRotate(rotationWithPerspective, 22.5, 0, 1, 0);
preview.layer.transform = rotationWithPerspective
生成透视图。然而,它出于某种原因翻转 View 。
1) 如何避免转换后的“翻转”?
2) 转换产生的“透视深度”对于每个给定的 UIView
是否都相同,还是取决于 UIView
大小等?
谢谢!
最佳答案
CATransform3DRotate
需要弧度而不是度数。您正在旋转 22.5 弧度,相当于 1200 度。这可能就是为什么你的图像是倒置的。你可能想使用这个:
let radians = 22.5 * M_PI / 180
rotationWithPerspective = CATransform3DRotate(rotationWithPerspective, radians, 0, 1, 0);
关于ios - 了解 CATransform3DRotate/CATransform3DMakeRotation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35446457/