UIView布局和applicationFrame

发布于 2024-09-11 11:17:39 字数 647 浏览 0 评论 0原文

我的 iPad 应用程序出现一些奇怪的行为。我通常会向我的 viewController 添加一个视图,如下所示:

CGRect bounds = [[UIScreen mainScreen] applicationFrame];
// Add Basic View
UIView *myView = [[UIView alloc] initWithFrame:bounds];
myView.backgroundColor = [UIColor blackColor];
self.view = myView;
[myView release];

在 iPhone 上,这总是很神奇。然而,在我的 iPad 应用程序上,我将一个工具栏添加到此 self.view 作为带有矩形 (0, 0, self.view.frame.width, 100) 的子视图。有时效果很好,工具栏显示在状态栏的正下方,但在某些情况下(例如,当 iPad 平放在桌子上且界面方向为纵向时),我的工具栏部分滑动到状态栏下方。然而,一旦我旋转设备,一切都会恢复正常,并且工具栏与状态栏正确对齐。

我尝试了一些解决方法,将值添加到工具栏的 origin.y 属性中,但当我这样做时,工具栏在旋转设备后会获得状态栏的偏移量。我对此感到非常困惑,有其他人遇到过这个问题吗?如果是这样,你是如何解决的?

多谢!

I am experiencing some weird behavior with my iPad app. I usually add a view to my viewController like this:

CGRect bounds = [[UIScreen mainScreen] applicationFrame];
// Add Basic View
UIView *myView = [[UIView alloc] initWithFrame:bounds];
myView.backgroundColor = [UIColor blackColor];
self.view = myView;
[myView release];

On the iPhone this always works like a charm. On my iPad app however, I add a toolbar to this self.view as a subview with the rectangle (0, 0, self.view.frame.width, 100). Sometimes this works out well and the toolbar displays right below the status bar, yet in certain conditions (eg. when the iPad is lying flat on a table and the interface orientation is portrait) my toolbar slides partly below the status bar. Yet as soon as I rotate the device everything is fine again and the toolbar is aligned properly with the status bar.

I have tried some workarounds with adding values a few points to the origin.y property of the toolbar, yet when I do this the toolbar gets an offset to the status bar after rotating the device. I am really confused by this, did anybody else ever experience this problem? If so, how did you fix it?

Thanks a lot!

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文