在 iPhone 中以编程方式向窗口添加视图时,看到屏幕底部出现白色条带吗?

发布于 2024-08-05 21:25:06 字数 113 浏览 6 评论 0原文

当我在 Xcode 中开发基于视图的项目时,我的视图工作正常。但是,当我使用基于窗口的项目并自己创建一个视图并尝试将其作为子视图添加到窗口时,它在底部给出了一条白色带。我以前从未遇到过这个问题,但还是第一次遇到。

When I developed a view based project in Xcode, My view works fine. But when I use a window based project and create a view on my own and try adding it as a subview to window, it gives me a white band at the bottom. I never faced this issue before but facing it first time.

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

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

发布评论

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

评论(4

软糯酥胸 2024-08-12 21:25:06

您应该始终通过从 UIScreen 获取分辨率来设置视图大小,

UIView *controllersView = [myViewController view]; // get the view
[controllersView setFrame:[[UIScreen mainScreen]applicationFrame]]; // set the Framesize

这会自动将原点设置为 x=0 和 y=20。请记住,您应该使用此方法,而不是手动将原点设置为 y=20,因为屏幕分辨率可能会发生变化,就像新的 iPhone 4 一样。

有趣的是,即使是 Apple 的 iPhone 的 HelloWorld 示例也有没有正确设置视图框架的 20 像素错误。

you shoud always set the View Size by getting the resolution from UIScreen

UIView *controllersView = [myViewController view]; // get the view
[controllersView setFrame:[[UIScreen mainScreen]applicationFrame]]; // set the Framesize

This automatically sets the origin to x=0 and y=20. Keep in mind, that you should use this method instead of manually setting the origin to y=20 because screen resolution can change as it will be with the new iPhone 4.

The funny thing is, that even Apple's HelloWorld Example for the iPhone has got the 20 pixels bug without setting the views Frame correctly.

Smile简单爱 2024-08-12 21:25:06

如果有人需要知道,偏移原点的代码将如下所示:

CGRect frame = myController.view.frame;
frame.origin.y = 20.0;
myController.view.frame = frame;

In case somebody needs to know, the code to offset the origin would look something like this:

CGRect frame = myController.view.frame;
frame.origin.y = 20.0;
myController.view.frame = frame;
冷血 2024-08-12 21:25:06

最有可能发生的情况是,您正在向窗口添加一个大小适合使用状态栏的视图,其大小包括状态栏。

iPhone 的屏幕高 480 像素,其中顶部 20 像素分配给设备的状态栏(带有信号强度/WiFi 指示器、时钟等的状态栏)。通常,视图的大小将根据窗口的剩余 460 像素进行调整,如果您正在开发基于视图的应用程序,那很好 - 该应用程序模板已经提供了一个 320x460 根视图,所有其他子视图都将添加到该视图中。

但由于您要添加到横跨整个屏幕 480 像素的窗口,我猜测您的视图仅短了 20 像素。尝试更改视图的高度,或设置其 y 偏移。

Most likely what is happening is that you're adding a view sized appropriately for using a status bar to the window, whose size includes the status bar.

The iPhone's screen is 480px high, and the top 20px of that are allocated for the device's status bar (the one with the signal strength/WiFi indicator, clock, etc.). Normally, a view will be sized for the remaining 460px of the window, and if you're developing a view-based app, that's fine - that application template already provides a 320x460 root view that all your other subviews get added to.

But since you're adding to the window, which spans all 480px of the screen, my guess is that your view is just 20px too short. Try changing the height of the view, or setting its y-offset.

忆梦 2024-08-12 21:25:06

如果您使用界面生成器,您可以单击视图,转到属性检查器并将状态栏更改为无。然后,您只需在尺寸检查器中将视图的高度调整为 480。

If you're using interface builder you can click on the view, go to attribute inspector and change status bar to none. You then simply need to adjust the height of the view in the size inspector to 480.

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