UITableViewController 和安全区域
UITableViewController and safe area
我正在使用 UITableViewController
的子类来支持我非常简单的 table 视图控制器。像这样:
class FriendsViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
tableView.insetsContentViewsToSafeArea = true
}
}
但是,table 视图覆盖了安全区域。当我在 iPhone X 模拟器上预览时,这一点尤为明显。
我希望看到这样的内容:
我尝试使用 tableView.insetsContentViewsToSafeArea
,按照我上面的代码片段,但它没有按照 Apple 文档所说的去做:
When the value of this property is true (the default), the table view adjusts the insets of the content view within each of its cells, headers, and footers on the leading and trailing sides to make the content fit within the safe area.
我知道没有 UITableViewController
的替代解决方案,但我特别想使用它(它非常方便)并且希望能够对其进行调整以使其正常运行并观察安全区域。令人难以置信的是,Apple 设计了一个损坏的组件。
无论如何,none 有类似问题的帖子有所帮助,所以希望重新开始。
您所看到的是正常且正确的。 table 视图是视图控制器的整个视图,覆盖了整个屏幕。它仍然可以正常工作,因为滚动内容是插入的,因此用户可以滚动查看 table; 的所有部分; table 的顶部向下插入。所以一切都很好。
如果您真的想要上一个屏幕截图中显示的效果,您必须将 table 视图控制器设为其他视图控制器的子视图控制器。典型的界面是将 table 视图控制器包裹在导航控制器中,以便导航栏填充屏幕顶部。或者您可以手动使用容器视图/嵌入 segue。
我正在使用 UITableViewController
的子类来支持我非常简单的 table 视图控制器。像这样:
class FriendsViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
tableView.insetsContentViewsToSafeArea = true
}
}
但是,table 视图覆盖了安全区域。当我在 iPhone X 模拟器上预览时,这一点尤为明显。
我希望看到这样的内容:
我尝试使用 tableView.insetsContentViewsToSafeArea
,按照我上面的代码片段,但它没有按照 Apple 文档所说的去做:
When the value of this property is true (the default), the table view adjusts the insets of the content view within each of its cells, headers, and footers on the leading and trailing sides to make the content fit within the safe area.
我知道没有 UITableViewController
的替代解决方案,但我特别想使用它(它非常方便)并且希望能够对其进行调整以使其正常运行并观察安全区域。令人难以置信的是,Apple 设计了一个损坏的组件。
无论如何,none 有类似问题的帖子有所帮助,所以希望重新开始。
您所看到的是正常且正确的。 table 视图是视图控制器的整个视图,覆盖了整个屏幕。它仍然可以正常工作,因为滚动内容是插入的,因此用户可以滚动查看 table; 的所有部分; table 的顶部向下插入。所以一切都很好。
如果您真的想要上一个屏幕截图中显示的效果,您必须将 table 视图控制器设为其他视图控制器的子视图控制器。典型的界面是将 table 视图控制器包裹在导航控制器中,以便导航栏填充屏幕顶部。或者您可以手动使用容器视图/嵌入 segue。