gpt4 book ai didi

ios - UITabBarController 的子 UIViewControllers 重叠状态栏

转载 作者:搜寻专家 更新时间:2023-10-31 19:33:57 25 4
gpt4 key购买 nike

  • Xcode 7
  • iOS 目标 9.3
  • swift 2

我在 Xcode 中创建了一个新的选项卡式应用程序:

enter image description here

我将第一个模板生成的 UIViewController super View 的背景更改为灰色,然后运行该应用程序,正如您在此屏幕截图中看到的那样,第一个 UIView 被状态栏重叠:

enter image description here

我读过很多文章,特别是针对 iOS 7 的关于为状态栏分配空间的文章。

我还阅读了 apple.developer.com以下引述:

“使用不透明 UINavigationController 或 UITabBarController 的应用程序会自动将其内容保持在状态栏下方。”

一般来说,apple.developer.com 网站上的这个链接似乎有点过时了。

但是,话虽如此,我希望 UITabBarController 加载选项卡式 subview ,并为 UITabBarController 的 Storyboard 中显示的状态分配空间:

enter image description here

我尝试将以下内容添加到我的 UITabBarController 类中:

override func viewDidLoad() {
super.viewDidLoad()

self.edgesForExtendedLayout = UIRectEdge.None
self.automaticallyAdjustsScrollViewInsets = false;
}

我看了很多 Stackoverflow 问答帖,发现这个人在 Stackoverflow 上问了同样的问题: Using UITabBarController but status bar covers view

我确实知道如何为每个 UiViewController 选项卡中的每个父 View 的顶部布局指南添加约束,但我试图避免添加新的顶级 UIView,因为我现有的 UIViewControllers 选项卡都有 UILabel、UIButtons、 SuperView 中的 UICollections 等我无法在 Xcode Storyboard中向 SuperView 的顶部布局指南添加约束。

对于 SuperView,我似乎无法通过控制拖动来添加顶级约束:

enter image description here

最佳答案

iOS 会在自动布局中为您处理此问题。当 View 延伸到状态栏下方时,将“垂直间距到顶部布局指南”约束中的约束固定为 0 距离,您会发现它按预期位于状态栏下方。

enter image description here

enter image description here

关于ios - UITabBarController 的子 UIViewControllers 重叠状态栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37901437/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com