将 UIView 坐标转换为横向

发布于 2024-12-05 03:13:29 字数 701 浏览 0 评论 0原文

我的屏幕上有一个 UILabel,当前为纵向。然而,我在上一层中渲染了一个 3D 场景,无论如何,它都是横向呈现的。我怎样才能将标签的点设置为 0,0;并使其在 0,0 处可见;就像在风景中一样。我认为它需要旋转 90 度,然后将轴反转。

我写了一些代码,但它没有像我希望的那样工作。

control.transform = CGAffineTransformRotate(CGAffineTransformIdentity, M_PI/2);

CGRect newFrame = CGRectMake(oldFrame.origin.x, oldFrame.origin.y, control.frame.size.width, control.frame.size.height);

newFrame.origin.y = 320 - (newFrame.origin.y - control.frame.size.width);

//invert the x and y axis
CGFloat x1 = newFrame.origin.y;
CGFloat y1 = newFrame.origin.x;
CGFloat w1 = newFrame.size.width;
CGFloat h1 = newFrame.size.height;

control.frame = CGRectMake(x1, y1, w1, h1);

我对此真的很困惑!

任何帮助表示赞赏。

I have a UILabel on the screen, which is currently in portrait. However, I have a 3D scene rendered in the previous layer, which is presented landscape regardless. How would I be able to set the point of the label at 0,0; and have it be visible at 0,0; as if it was in landscape. I figure it would need to be rotated 90 degrees, and then have the axis inverted.

I've written some code, but it doesn't work as I had hoped.

control.transform = CGAffineTransformRotate(CGAffineTransformIdentity, M_PI/2);

CGRect newFrame = CGRectMake(oldFrame.origin.x, oldFrame.origin.y, control.frame.size.width, control.frame.size.height);

newFrame.origin.y = 320 - (newFrame.origin.y - control.frame.size.width);

//invert the x and y axis
CGFloat x1 = newFrame.origin.y;
CGFloat y1 = newFrame.origin.x;
CGFloat w1 = newFrame.size.width;
CGFloat h1 = newFrame.size.height;

control.frame = CGRectMake(x1, y1, w1, h1);

I'm really confused about this!

Any help appreciated.

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

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

发布评论

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

评论(2

横笛休吹塞上声 2024-12-12 03:13:29

您应该尽量不要混合纵向和横向。
尝试使用仅允许横向的 UIViewController;定位标签会容易得多。

You should try not to mix portrait and landscape.
Try using a UIViewController that only allows landscape; positioning the label would be much easier.

許願樹丅啲祈禱 2024-12-12 03:13:29

UIView 类有两种方法将点从一种视图转换为另一种视图。这些方法考虑了视图转换。

convertPoint:toView:
convertPoint:fromView:

The UIView class has two methods for converting points from one view to another. These methods take into account the views transformations.

convertPoint:toView: and
convertPoint:fromView:

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