UITableView extra space at bottom

后端 未结 11 598
被撕碎了的回忆
被撕碎了的回忆 2020-12-15 20:15

My tableview has an extra space at the bottom, as you see in the picture:

All the rows in the tableView have a fixed height of 71pt.

11条回答
  •  悲&欢浪女
    2020-12-15 20:39

    @urgentx's answer did most of what I wanted but didn't get all the way there. I'm in a similar situation (upside down UITableView for a chat app) however their suggestion fully disables safe area behavior which isn't desirable on devices like the iPhone X because it means the tableview will be clipped by both the home indicator and any top navigation bars.

    I did the following in order to make the tableview still correctly avoid safe areas while inverted:

    override func viewDidLoad() {
        super.viewDidLoad()
        self.automaticallyAdjustsScrollViewInsets = false
        self.tableView.contentInsetAdjustmentBehavior = .never
    }
    

    and then:

    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
        //fetch the safe area in layoutSubviews since this it's possible that they can change when the device is rotated
        let safeArea = self.tableView.safeAreaInsets
        //insets are **flipped** because the tableview is flipped over its Y-axis!
        self.tableView.contentInset = .init(top: safeArea.bottom, left: 0, bottom: safeArea.top, right: 0)
    }
    

    This in essence replicates contentInsetAdjustmentBehavior = .automatic behavior but with the insets flipped across the Y-axis.

提交回复
热议问题