似乎 UITableViewController 没有安全区域布局指南来将表格 View 顶部和底部边距设置为与 iPhone X 中的底部布局折叠。所有 View Controller 都可以与 Storyboard中的安全区域布局指南正常工作,以实现顶部和底部边距。 UITableView Controller 除外。
作为引用,我附上了 iPhoneX 的屏幕截图。在那里您可以看到字符串“wheat”不适合底部安全区域。
最佳答案
我相信会发生这种情况,因为 View Controller 的 View (始终占据整个屏幕大小)是tableview
。
使用 UIViewController
并在其 view
下添加表格 View (并添加约束以尊重底部安全区域)
或
设置表格 View 内容插入:
tableView.contentInset = UIEdgeInsetsMake(0, 0, UIApplication.shared.keyWindow!.safeAreaInsets.bottom, 0.0);
如果您使用后者且目标 iOS 版本低于 11,请确保使用以下方式进行验证:
var safeAreaBottom: CGFloat = 0.0
if #available(iOS 11.0, *) {
safeAreaBottom = UIApplication.shared.keyWindow!.safeAreaInsets.bottom
}
tableView.contentInset = UIEdgeInsetsMake(0, 0, safeAreaBottom, 0.0);
我还注意到 iOS 11 中 tableview
的这个属性(但没有描述:/):insetsContentViewsToSafeArea
我还没尝试过,但你可以尝试一下。也许这就是您开箱即用的需求
关于ios - 安全区域布局指南不适用于 Storyboard中的 UITableViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47816496/