Search code examples
iosswiftuiscrollview

content offset doesn't work


I am trying to set the content offset in my uiscrollview. I have tried the following, and none of it works. None of the following affect my scrollView in any way, it simple appears on the screen as normal.:

 let point = CGPoint(x: 0, y: self.view.frame.height / 2)
 self.scrollView.setContentOffset(point, animated: true)

and:

 self.scrollView.contentOffset.y = self.view.frame.size.height / 2

and:

 self.scrollView.contentOffset = CGPointMake(0, self.view.frame.size.height / 2)

and:

 self.scrollView.contentOffset = CGPointMake(0, scrollView.frame.size.height / 2)

I have a scroll view that is 2 times the height of my view. They are essentially separated into 2 different view that I can page between. I want the scrollview to start on the bottom part.


Solution

  • You should try them in the viewDidLayoutSubviews

    Ref: iOS 9 scroll UITextView to top