Reputation: 6918
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:
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:
Upvotes: 0
Views: 354
Reputation: 3718
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;
Upvotes: 1
Reputation: 1889
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.
Upvotes: 1