UITextView scrolling while editing?

I have a large UITextView , almost full screen. If I touch it, a keyboard will appear and I can edit the text. However, the longer I type, the faster the text flows in kind, behind the keyboard. I can no longer see what I'm typing.

How do you deal with this? Do I need to track the cursor position and scroll the view manually?

+6
source share
3 answers

I assume that you need to configure your UITextView as showing / hiding the keyboard. So the keyboard will not be above your text. Here is a sample code.

 - (void)viewDidLoad { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; } - (void)keyboardWillShow:(NSNotification *)notification { [UIView beginAnimations:nil context:nil]; CGRect endRect = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; CGRect newRect = YOUT_TEXT_VIEW.frame; //Down size your text view newRect.size.height -= endRect.size.height; YOUT_TEXT_VIEW.frame = newRect; [UIView commitAnimations]; } - (void)keyboardWillHide:(NSNotification *)notification { ... // Resize your textview when keyboard is going to hide } 
+5
source

You need to use the following code to scroll down the text according to the text range (or say according to type)

 NSRange range = NSMakeRange(textView.text.length - 1, 1); [textView scrollRangeToVisible:range]; 

Hope this helps you ...

+7
source

TPKeyboardAvoiding is a great tool that handles all scrolling to avoid the keyboard for you. / Very / convenient and highly recommended. See: https://github.com/michaeltyson/TPKeyboardAvoiding

+2
source

Source: https://habr.com/ru/post/914953/


All Articles