Hi everyone,
I have a UITextView that I've created programmatically and manually added as a subview to a UIView. When I click on the UITextView, the keyboard appears and the UITextView gets resized to fit inside the smaller screen real estate. My problem arises when I dismiss the keyboard. For whatever reason, I can't get the UITextView to refill the entire screen.
I'm resize the text view by changing the frame from within the keyboardWillShow and keyboardWillHide notifications. The first resize (when keyboardWillShow is called) seems to work fine, but the second resize (when keyboardWillHide is called) apparently does nothing.
Does anyone know why this isn't working? Are there any alternatives to make this happen? My code is below. Thanks for any help you guys can offer!
Code:
- (void)loadView
{
textView = [[UITextView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.bounds.size.width, self.view.bounds.size.height)];
textView.delegate = self;
textView.backgroundColor = [UIColor whiteColor];
textView.scrollEnabled = YES;
// this will cause automatic vertical resize when the table is resized
textView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self.view addSubview:containerView];
}
- (void)viewWillAppear:(BOOL)animated
{
// watch the keyboard
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification object:self.view.window];
// watch the keyboard
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification object:self.view.window];
}
- (void)keyboardWillShow:(NSNotification *)notif
{
// The keyboard will be shown. Modify the textView size to fit the smaller screen.
textView.frame = CGRectMake(0.0, 0.0, self.view.bounds.size.width, 200);
}
- (void)keyboardWillHide:(NSNotification *)notif
{
// The keyboard will be shown. Modify the textView size to fit the larger screen.
textView.frame = CGRectMake(0.0, 0.0, self.view.bounds.size.width, 400);
}