将 UIView 坐标转换为横向
我的屏幕上有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该尽量不要混合纵向和横向。
尝试使用仅允许横向的 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.
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: