When I have text that does not fill the UITextView, it is scrolled to the top working as intended. When there is more text than will fit on screen, the UITextView is scrolle
This is an interesting bug. In our project, this is only occurring on devices with an iPhone 5
-size screen. It appears that the textview contentOffset
changes at some point during the view controller lifecycle. In viewDidLoad
and viewWillAppear
the textview's contentOffset
is 0,0
, and by viewDidAppear
it's changed. You can see it happening in viewWillLayoutSubviews
. Constraints appear to be set up correctly.
This will ensure you don't call a scrolling method unless it's needed:
if textView.contentOffset.y > 0 {
textView.contentOffset = CGPoint(x: 0, y: 0)
// Or use scrollRectToVisible, scrollRangeToVisible, etc.
}