MichiZH
MichiZH

Reputation: 5807

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?

Upvotes: 7

Views: 2523

Answers (3)

Bjørn Ruthberg
Bjørn Ruthberg

Reputation: 344

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

Upvotes: 3

ScottyBlades
ScottyBlades

Reputation: 13973

This will make it so the contents shift up.
If you want them to shift down you can change the insets accordingly.

    func shiftScrollingUp() {
        yourScrollView.contentInsetAdjustmentBehavior = .never
        yourScrollView.contentInset = UIEdgeInsetsMake(0, 0, 150, 0)
    }

AutomaticallyAdjustsScrollViewInsets is deprecated in ios 11.

Upvotes: 0

BFar
BFar

Reputation: 2497

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);

Upvotes: 7

Related Questions