Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: Table view, allow scrolling "further down" than the end

Sorry the question sounds a bit confusing. I have two buttons overlapping my table view at the bottom, so if the table view scrolls "normal" the last row is partially hidden by these buttons. That's why I want to allow scrolling the table like the height of one row further down, so the last row is on top of these two buttons. How can I achieve this?

like image 980
MichiZH Avatar asked Jan 09 '15 13:01

MichiZH


Video Answer


2 Answers

Adjust the content insets of the table view.

For instance, if your buttons are 50 points in height and your table's frame is the full window, you could set your table to snap to the top of your buttons like this:

tableView.contentInset = UIEdgeInsetsMake(0, 0, 50, 0);

Note: In iOS 7+ view controllers have a property automaticallyAdjustsScrollViewInsets that is set to YES by default. When this property is set to YES, the contentInsets you set manually may be overridden. Assuming you have a nav bar of some kind that you want to scroll under, you can set your top edge inset to the length of the topLayoutGuide.

Your final solution (put this in viewDidLoad):

self.automaticallyAdjustsScrollViewInsets = NO;
tableView.contentInset = UIEdgeInsetsMake(self.topLayoutGuide.length, 0, 50, 0);
like image 114
BFar Avatar answered Oct 03 '22 14:10

BFar


As pointed out by others, deprecations have made this solution impossible, and if we use a section footer, this will display at the inset all the time. A much simpler solution would be to add a tableFooterView to allow the bottom cells to scroll past the buttons. Like so:

    let bottomView = UIView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: 83))
    bottomView.backgroundColor = .clear
    tableView.tableFooterView = bottomView
like image 41
Bjørn Ruthberg Avatar answered Oct 03 '22 13:10

Bjørn Ruthberg