我正在根据 iPhone 的方向旋转 3D 图像,代码如下:它有效。
我的问题是:
这是一种可以接受的方法吗?
是否可以使用单个命令而不是依次构建三个 CATransform3DRotate。
我应该更改 .m34 值吗? 1.0 / -500 似乎用得很多,但我不太明白它的解释:https://en.wikipedia.org/wiki/3D_projection#Perspective_projection
let layer = panelView.layer
var rotationAndPerspectiveTransform = CATransform3DIdentity
rotationAndPerspectiveTransform.m34 = 1.0 / -500
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, CGFloat(roll * .pi / 180), 0.0, 0.0, 1.0) // roll
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, CGFloat(pitch * .pi / 180), 1.0, 0.0, 0.0) // pitch
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, CGFloat(yaw * .pi / 180), 0.0, 1.0, 0.0) // yaw
UIImageView.animate(withDuration: 0.5, delay: 0, options: [], animations: {
layer.transform = rotationAndPerspectiveTransform
})