UITextView, scroll while editing?

cocoa-touch, ios, keyboard, uitextview

Solution

I guess you have to size your UITextView as keyboard shows/hides. So the keyboard won't be over your textview. Here is the sample codes.

- (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
}

Problem

I've got a big `UITextView`, nearly full screen. If I tap it, the keyboard pops up and I can edit the text. However, the longer I type, eventually the text runs down the view, behind the keyboard. I can no longer see what I'm typing. How do you deal with this? Do you have to track the cursor position and scroll the view manually?

Original source