ios - 了解 CATransform3DRotate/CATransform3DMakeRotation

标签 ios swift object calayer catransform3drotate

我正在尝试了解如何像这样为我的 UIView 创建深度感知:

enter image description here

我试过这段代码:

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/

相关文章:

iphone - 使用 GCD 填充 TableView 单元格

ios - 你如何在 Xcode 中使用 Flutter Flavors

ios - 如果使用 CKFetchRecordZoneChangesOperation 时应用程序被终止,会发生什么?

swift - 始终将数据保存在第一个 Cell UICollectionView 中

c++ - 如何将一个对象的多个实例发送到一个函数中

javascript - 通过嵌套对象 JavaScript 计时递归迭代

ios - 我必须下载大量大尺寸图像并在表格 View 中显示?

iphone - 如何在 2 个或更多 ios 设备上同步音频

ios - 除非我添加另一个 UIView,否则 ScrollView 中的 TableView 为空?

java - 将对象克隆到数组列表中,java