创建位于平面上的矩形的透视图

发布于 2024-10-14 04:53:29 字数 635 浏览 4 评论 0原文

我已经在 Objective-C 中工作了一段时间,但我(直到现在)还没有真正需要深入研究核心动画和图形操作。

我目前有四个 UIImageView,我想将它们设置为动画,使它们看起来像是躺在平坦的表面上。我的意思是,它们将以矩形开始 - 不扭曲且平坦地显示在屏幕上,但会动画成倾斜的视角,使其看起来像是坐在平坦的表面上。

我相信 CATransform3D 是我需要做的,并且已经阅读了许多文档,这些文档都指向使用 .m34 创建正确的视角。我似乎无法让它发挥作用。下面是我用来尝试使图像倾斜的代码片段。当我使用下面的代码时,只是尝试倾斜图像,它似乎将其切断而不是显示正确的视角。

CATransform3D transform = CATransform3DIdentity; 
transform.m34 = -1.0f / 700.0f;
// Perform other transforms
transform = CATransform3DRotate( transform,
    degreesToRadians(45.0f), 0.0f, 1.0f, 0.0f);

[layer setTransform:transform];

我可以很好地处理动画,但无法使最终图像倾斜以使其看起来正确。有人对如何实现这一目标有任何建议或示例吗?

I have been working in objective-c for a while now, but I haven't really had a need (until now) to dive deeper into core animation and graphic manipulation.

I currently have four UIImageViews that I want to animate into a position that makes them look like they are lying down on a flat surface. What I mean by that is that they will start as rectangles - undistorted and flat on the screen, but will animate into the skewed perspective that makes it look like they are sitting on a flat surface.

I believe that CATransform3D is what I need to do and have read a number of docs that all point to using .m34 to create the correct perspective. I just can't seem to get it to work. Below is a snippet of code that I am using just to try and get the image to skew. When I use the code below, just to try and skew the image, it seems to cut it off instead of showing the right perspective.

CATransform3D transform = CATransform3DIdentity; 
transform.m34 = -1.0f / 700.0f;
// Perform other transforms
transform = CATransform3DRotate( transform,
    degreesToRadians(45.0f), 0.0f, 1.0f, 0.0f);

[layer setTransform:transform];

I can handle the animations fine, but am having trouble getting the final image skewed so that it looks correct. Anyone have any suggestions or samples on how to achieve this?

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

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

发布评论

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

评论(1

沫雨熙 2024-10-21 04:53:29

动画对我来说看起来有偏差。尝试使用 m34 因子进行试验以使其倾斜更多(将其设置为较低的值,例如 -1.0f/200.0f)。只要尝试一下,你最终就会得到正确的结果。如果您希望其倾斜程度更大,可以将旋转更改为 45 度以外的角度。

如果您的转换根本不倾斜,那么您的其他转换之一可能会覆盖该转换(即您正在使用 Make 转换调用之一)。如果是这样:尝试将transform.m34分配移到应用变换之前的最后一件事。

The animation looks skewed to me. Try experimenting with the m34 factor to make it skew more (setting it to a lower value like -1.0f/200.0f). Just experiment and you will eventually get it right. You can change to rotation to something else than 45 degrees if you want it to skew more.

If your transform doesn't skew at all then maybe one of your other transforms are overwriting the transform (I.e you are using one of the Make transform calls). If so: try moving the transform.m34 assignment to be the last thing before applying the transform.

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