我正在使用以下代码来旋转 UIView 的 z 方向。它在右侧旋转。但我想旋转底部而不是右侧(因为它在右侧)。
UIView *myView = self.view;
CALayer *layer = myView.layer;
CATransform3D transform = CATransform3DIdentity;
transform.m34 = 1.0 / -2000;
CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
rotationAndPerspectiveTransform.m34 = 1.0 / -500;
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, 45.0f * M_PI / 180.0f, 0.0f, 1.0f, 0.0f);
layer.transform = rotationAndPerspectiveTransform;
您看过
CATransform3DRotate
函数采用的参数吗?
最后三个元素定义视图将翻转的向量。你的向量平行于 y 轴。尝试这个来绕垂直轴旋转。
rotationAndPerspectiveTransform = CATransform3DRotate(
rotationAndPerspectiveTransform,
45.0f * M_PI / 180.0f,
1.0f, 0.0f, 0.0f);
您可能需要更改锚点以使轴位于正确的“高度”。