iPad 应用程序中 UIView 框架更改坐标

发布于 2025-01-05 02:05:03 字数 552 浏览 1 评论 0原文

强文本我有一个 iPad 应用程序,它只允许横向方向,并以横向方向启动。我有一个 UIViewController ,在 viewDidLoad 中我设置了视图的框架:

self.view.frame = CGRectMake(0, 0, 1024, 728);

在同一个 UIViewController 中的 touchesBegan 函数中code> 我打印出视图:

NSLog(@"%@",self.view);

当我点击屏幕时得到:

<UIView: 0x37e370; frame = (0 0; 768 1024); transform = [0, 1, -1, 0, 0, 0]; layer = <CALayer: 0x37e3d0>>

如您所见,框架更改为 [0,0,768,1024] (这是纵向 iPad)而不是 [0,0,1024,728] (这是我在 viewDidLoad 方法中定义的)。

为什么它会针对我?

strong textI have an iPad app which only allows landscape orientation, and launches in landscape orientation. I have a UIViewController and in the viewDidLoad I set the frame of the view:

self.view.frame = CGRectMake(0, 0, 1024, 728);

In a touchesBegan function in that same UIViewController I print out the view:

NSLog(@"%@",self.view);

and when I tap the screen get:

<UIView: 0x37e370; frame = (0 0; 768 1024); transform = [0, 1, -1, 0, 0, 0]; layer = <CALayer: 0x37e3d0>>

As you can see, the frame changes to [0,0,768,1024] (which is portrait iPad) instead of [0,0,1024,728] (which is what I defined it to be in the viewDidLoad method).

Why is it switching on me?

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

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

发布评论

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

评论(1

山有枢 2025-01-12 02:05:03

这与你的另一个问题有关,不是吗? iPad Landscape 开始弄乱触摸

引用你的答案:
”的一点是,在定义UIWindow时,需要将其定义为

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

而不是严格的坐标。

This is related to this other question of yours, no? iPad Landscape messing up touches began

Quoting your answer:
" is that, when defining the UIWindow, it needs to be defined as

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

and not strict coordinates.
"

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