convertPoint:toView:在横向模式下给出错误的值 [英] convertPoint:toView: in landscape mode giving wrong values

查看:271
本文介绍了convertPoint:toView:在横向模式下给出错误的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个以风景模式创建的视图(长时间旋转等)。

在此视图中,我想找到一个相对于主窗口的点。

以下代码在纵向模式下工作,但在landscappe中,它仍然返回值,就像是在纵向。

I have a view which is created in landscape mode (long after rotation etc.).
In this view, I want to find a point relative to the main window.
The following code works in portrait mode, but in landscappe it still returns values as if it were in portrait.

CGPoint ptRelativeToWindow = [self convertPoint:self.bounds.origin toView:nil];

已解决

这解决了问题,并提供了正确的坐标:

This solved the problem and gives the right coordinates:

[self convertPoint:self.bounds.origin toView:[UIApplication sharedApplication].keyWindow.rootViewController.view];


推荐答案

不能使用主窗口计算相对坐标。主窗口接收旋转事件并将它们传递到控制器,这意味着它不改变大小本身(总是有相同的纵向边界)。这就是为什么你发现的解决方案是有道理的:你找到相对于根控制器的视图的坐标,它接收旋转事件并相应地改变它的大小。

You can't use main window to calculate relative coordinates. Main window receives rotation events and passes them onto controllers which means it doesn't change the size itself (always has the same portrait bounds). That's why the solution you found makes sense: you find the coordinates relative to the view of the root controller which does receive rotation events and changes its size accordingly

这篇关于convertPoint:toView:在横向模式下给出错误的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆