Question

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

Was it helpful?

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;

OTHER TIPS

This is not weird at all :)

You can do this by registering as an observer to the UIKeyboardWillShowNotification (it would be a good idea to also register for the UIKeyboardWillHideNotification in the same process).

When the registered selector will be called, the notification parameter will contain the keyboard's size inside the UIKeyboardFrameEndUserInfoKey value of the userInfo dictionnary :

[[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size

All you need to do now is to set the frame of your UITextView to your desired size.

Be warned : the CGRect you get does not take into account the device orientation. This means, if the device is in fact in landscape mode, you'll need to switch the width and height of the CGRect for it to make sense in your context.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top