2
votes

I have a simple UITextView that occupies all the screen. When the text length is bigger than the Textview height, it automatically scrolls to the bottom (see image).

I have already tried

self.textView.scrollRangeToVisible(NSMakeRange(0, 0))

and

self.textView.scrollsToTop = true

and other things without any result.

I'm using iOS 9 with the latest swift and Xcode 7.1.1.

2

2 Answers

1
votes

I've found a solution.

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()

    self.textView.setContentOffset(CGPoint.zero, animated: false)
}

but I still don't understand why it didn't work.

0
votes

You also try

 self.textView.scrollRangeToVisible(NSRange(location:0, length:0))