TableView and the home indicator on iPhone X

送分小仙女□ 提交于 2019-12-01 06:20:35

You can continue to use a UITableView on a standard UIViewController. Just set auto layout so the bottom of the tableview is flush with the bottom of the superview (and not the margin). Then set the insetsContentViewsToSafeArea property of the tableview to true

Swift:

if #available(iOS 11.0, *) {
    tableView.insetsContentViewsToSafeArea = true;
}

Objective-C:

if (@available(iOS 11.0, *)) {
    [tableView setInsetsContentViewsToSafeArea:YES];
}

This is what worked for me, in iOS 12:

I tried setting insetsContentViewsToSafeArea but that didn't work, although it set me on the right path. What fixed it for me was setting the "Content Insets" in the nib/storyboard to "Never" (in the code, that property is contentInsetAdjustmentBehavior).

Explanation: It seems that, for iPhoneX and above, the system automatically adds some bottom padding for table views so that the content goes above the home indicator.

This is because table view in UITableViewController is root view. It will extend to full screen. But you can make constraints to bottom layout guide for table view in UIViewController. So you can use UIViewController. Or you can set content insets in UITableViewController.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!