Niall Kehoe
Niall Kehoe

Reputation: 379

UIScrollView Scrolling Up

I'm trying to get a UIScrollView to scroll upwards instead of downwards.I have everything set up except I don't know what line I should use to accomplish this. What should I do?

Niall

Upvotes: 0

Views: 56

Answers (1)

Forest Kunecke
Forest Kunecke

Reputation: 2160

What I think you mean by this is that you want a scrollView that starts at the bottom and your content can be accessed by scrolling up.

In this case you simply need to figure out how large your content is, and set the setContentOffset of your scrollView to the height of your content:

override func viewDidLoad() {
    // other code here...

    // set the contentSize of the scrollView somewhere in here...

    // get the offset based on the size of the content
    let bottomOffset = CGPoint(x: 0, y: scrollView.contentSize.height - scrollView.bounds.size.height)
    // do not animate because we want to immediately scroll to the bottom
    scrollView.setContentOffset(bottomOffset, animated: false)

This code is adapted from this answer.

Upvotes: 1

Related Questions