iOS 7 |导航栏/工具栏按钮非常接近状态栏 [英] iOS 7 | Navigation bar / Toolbar buttons very close to status bar
问题描述
将导航栏或工具栏(故事板)拖到我的视图控制器时遇到问题.
I have a problem when dragging a navigation bar or toolbar (storyboard) to my view controller.
UINavigationBar:
UINavigationBar:
如上图所示,右侧按钮几乎与状态栏重叠.
As you can see in the image above, the right button is almost overlapping the status bar.
使用 UIToolbar 也会发生同样的情况:
With a UIToolbar it happens the same:
此视图控制器旨在用作模态,这就是我不使用 UINavigationController 的原因.
This view controllers are intended to be used as a Modal, that's the reason I'm not using a UINavigationController.
在另一部分中,我使用了 UINavigationController,它按我的预期显示:
In another section I use a UINavigationController and it appears as I expect:
如何将 UINavigationBar/UIToolbar 拖动到视图控制器而不与状态栏重叠?
推荐答案
导航栏或工具栏必须在 (0, viewController.topLayoutGuide.length
) 和 UIBarPositionTopAttached 栏定位代码>.您应该将导航栏或工具栏的委托设置为视图控制器,并返回
UIBarPositionTopAttached
.如果定位正确,您将在第三张图片中看到结果.
The navigation bars or toolbars have to be at (0, viewController.topLayoutGuide.length
) with bar positioning of UIBarPositionTopAttached
. You should set the delegate of your navigation bar or your toolbar to your view controller, and return UIBarPositionTopAttached
. If positioned correctly, you will have the result in your third image.
更多信息在这里:https://developer.apple.com/documentation/uikit/uibarpositioningdelegate?language=对象
这篇关于iOS 7 |导航栏/工具栏按钮非常接近状态栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!