Search code examples
iosuitextviewcgrect

Take CGRect out of UITextView


This must sound really weird but I want to take the keyboard's CGRect and take it out of the UITextView. Here is a picture to help:

Image

I basically want the UITextView to become smaller so when I add text it scrolls down. If you need more info ask me.

EDIT: When I use this code:

- (void)keyboardWasShown:(NSNotification*)notification {
      NSDictionary* info = [notification userInfo];
      kbSIZE = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
      CGRect newTextViewFrame = self.notesTextView.frame;
      newTextViewFrame.size.height -= kbSIZE.size.height;
      self.notesTextView.frame = newTextViewFrame;
 }

this happens:

imag2


Solution

  • Not that weird at all. The same thing often happens with tableviews when you are bringing up a keyboard. This bit of code should help.

    CGRect newTextViewFrame = textView.frame;
    newTextFrame.size.height -= keyboardSize.frame.size.height;
    textView.frame = newScrollFrame;