【问题标题】:iOS7 view with autolayout to line up above TabBar带有自动布局的 iOS7 视图在 TabBar 上方对齐
【发布时间】:2025-12-23 17:15:11
【问题描述】:

我知道我知道.. 另一个 iOS7 问题。
我在 UINavigationController 中有一个视图,它被添加到 TabBarController。 在 iOS6 中,我使用了垂直约束“超级视图的底部空间,默认值”,这会给我 10 个关于 TabBar 的像素。
这个相同的约束似乎在 iOS 7 中不起作用。 TabBar 不再被视为超级视图了吗?我应该使用其他约束吗?

【问题讨论】:

    标签: uinavigationcontroller uitabbarcontroller autolayout ios7


    【解决方案1】:

    如果您使用的是自动布局。请在 Interface Builder 中为您的 tabbarcontroller 取消选中“Extend Edges>Under Bottom Bars”设置。

    【讨论】:

      【解决方案2】:

      现在每个视图控制器都是全屏的,因此您的视图从 0,0(在状态栏下方)开始并在标签栏下方结束。

      通过自动布局,您可以在 UIViewController 中使用一个名为 bottomLayoutGuide 的新属性。正如iOS 7 UI Transitioning Guide 所说:

      topLayoutGuide 和 bottomLayoutGuide 属性指示视图控制器视图中顶部或底部条边的位置。如果 bar 应该与视图的顶部或底部重叠,您可以使用 Interface Builder 通过创建 topLayoutGuide 底部或 bottomLayoutGuide 顶部的约束来相对于 bar 定位视图。 (如果没有任何条与视图重叠,topLayoutGuide 的底部与视图的顶部相同,bottomLayoutGuide 的顶部与视图的底部相同。)这两个属性都是在请求时延迟创建的。

      【讨论】:

      • iOS7目前存在一个bug,在标签栏切换标签时,底部布局指南高度设置不正确。
      • topLayoutGuidebottomLayoutGuide 属性只能在使用 Storyboard 时从 Interface Builder 中访问,而在标准 NIB 中似乎...
      【解决方案3】:

      在 IOS 7 中:

      在tabbar的视图层次结构中,topView->parentView-> .... ->rootView

      对从顶部到根的每个视图执行以下操作::为每个视图添加约束left、top、right、bottom

      【讨论】: