Z方向UIView旋转?

发布于 2024-10-09 10:36:33 字数 527 浏览 0 评论 0原文

我正在使用以下代码来旋转 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;

I am using following code for rotating z direction the UIView. It rotates in right side. But I want to rotate bottom side instead of right side (as it is in right side).

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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽梦忆笙歌 2024-10-16 10:36:33

您是否查看过 CATransform3DRotate 函数采用的参数?

最后三个元素定义视图将翻转的矢量。你的向量平行于 y 轴。尝试使用此方法来绕垂直轴旋转。

 rotationAndPerspectiveTransform = CATransform3DRotate(
            rotationAndPerspectiveTransform, 
            45.0f * M_PI / 180.0f,
            1.0f, 0.0f, 0.0f);

您可能需要更改锚点以使轴位于正确的“高度”。

Have you looked at the parameters the CATransform3DRotate function takes?

The last three elements define the vector the view will flip around. Your vector is parallel to the y axis. Try this instead for the rotation around a vertical axis.

 rotationAndPerspectiveTransform = CATransform3DRotate(
            rotationAndPerspectiveTransform, 
            45.0f * M_PI / 180.0f,
            1.0f, 0.0f, 0.0f);

You might need to change the anchor point to get the axis on the right "height".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文