0
votes

I have a view controller that is basically a form with multiple UITextFields and UITextView, embedded in a UIScrollView. When an UITextField becomes first responder, the scroll view automatically move to the focused field, which is believe is the behaviour explained in the first answer in this topic :

Disable UIScrollView scrolling when UITextField becomes first responder

This does not happen when the first responder is an UITextView though, and I'm not sure why and how I should fix it.

The second problem is that when the keyboard is shown, the scroll view does not scroll if the UITextView is not in view (because it's hidden by the newly shown keyboard). I implemented the code of Apple's documentation on how to manage the keyboard :

http://developer.apple.com/library/ios/#DOCUMENTATION/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html

And added another activeField variable named activeView for textViews (initialized in the beginEditing of TextView, set to nil in endEditing, and scrollToVisible according to it's frame when the keyboard is shown). The problem here is that the beginEditing in UITextView is called after the keyboardWasShown, so the activeView is not initialized and thus does not scroll. For some reason, for UITextFields the beginEditing is called before, which is the intended behaviour.

How can I scroll to an UITextView and it's the first responder, and how can I move to it when the keyboard is shown and hide it?

1

1 Answers

0
votes

To scroll to show anything in a UIScrollView do

scrollRectToVisible:/*frame of object you want to show*/ animated:YES

Subscribe to UITextViewTextDidBeginEditingNotification and call the above method when you get it.