Obiwahn
Obiwahn

Reputation: 3087

UITextView scrolls to top on hiding keyboard in iOS 8

My UITextView uses attributet text. When I call resignFirstResponder it always scrolls to the top.

This only happens on my iOS 8 Simulator. Not my iOS 7 phone.

Any idea to prevent this?

Upvotes: 3

Views: 972

Answers (1)

Eclectic DNA
Eclectic DNA

Reputation: 386

I think I found a work around to this.

First, instead of calling resignFirstResponder I'm now calling [textView setEditable:NO] to dismiss the keyboard.

There seems to be a bug when initializing UITextViews in iOS 8. Long story short, the subview (of my UITextView) UITextContainerView's minSize Y value was not being initialized to the same size as the UITextView's frame. It was set to 0 instead.

To force an initialization of that value, since it's not directly accessible, I found that calling [textView setScrollEnabled:NO] in viewDidLoad will set that Y to the same as my frame's size Y value, which fixed a lot of my scrolling issues in iOS 8.

I also had to set the scrolling back to enabled in viewDidAppear so that they'd still be scrollable.

Upvotes: 3

Related Questions