在 iPhone 中以编程方式向窗口添加视图时,看到屏幕底部出现白色条带吗?
当我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您应该始终通过从 UIScreen 获取分辨率来设置视图大小,
这会自动将原点设置为 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
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.
如果有人需要知道,偏移原点的代码将如下所示:
In case somebody needs to know, the code to offset the origin would look something like this:
最有可能发生的情况是,您正在向窗口添加一个大小适合使用状态栏的视图,其大小包括状态栏。
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.
如果您使用界面生成器,您可以单击视图,转到属性检查器并将状态栏更改为无。然后,您只需在尺寸检查器中将视图的高度调整为 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.