I'm developing a section of my app with a UITableView. I added it programmatically with this set of constraints. I'm not considering bottom safe area because I want content over it.
NSLayoutConstraint.activate([
tableView.topAnchor.constraint(equalTo: customHeader.bottomAnchor),
tableView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor),
tableView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor),
tableView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor)
])
So, I noticed this weird behavior of scroll indicator:
green is customHeader
, blue is the tableView background color and orange is the first cell. When I pull down the tableview and I reach the first cell, the scroll indicator is not at ZERO position, but only graphically. In fact tableView.scrollIndicatorInsets.top
is zero.
So I tried to set it to -20, for example, and the scroll indicator has its zero behind the customHeader
, as expected. So it starts to appear outside the tableView.
I tried to set tableView.scrollIndicatorInsets.top = .leastNonZeroMagnitude
and it works. Now the indicator starts at Zero.
I studied this behavior and I found that if I change the bottom constraint from:
tableView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor)
to:
tableView.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor)
everything works fine, without the need to set manually the scroll indicator position. But in this way I lose the possibility to have table view content over safe area. I thought it could be a problem of automaticallyAdjustScrollViewInsets
for the vc I'm working on, but it's not the case.
Any advice on this? I think it's a bug. I'm working with Xcode 11.4 and Swift 5.2.
Thanks.