Search code examples
objective-cxcodescrolluitextviewuitextviewdelegate

UITextView Scroll to selected line


I have a UITextView, and when i type in text, the keyboard will eventually hide the text so i can't see it, so i somehow need to move the text "up" while typing. So far, i got to the delegate method textViewDidChange: But still a bit lost?

Can anyone provide me with code snippets or clues to what i'm supposed to do here?

I tried something like

if (textView.text.length > 0.0) {
    NSRange range = NSMakeRange(textView.text.length - 1, 1);
    [textView scrollRangeToVisible:range];
}

But it doesn't work. It's a snippet i found on the site here, as i am new to working with the UITextView. So a working code snippet, i can then dissemble and work with is the best way for me to learn.

Thanks on advance


Solution

  • See this post How to make a UITextField move up when keyboard is present? This will move upwards your Textfields while typing.