Reputation: 4108
I've got a UITextview that covers the entire screen. To compensate for the keyboard I added this handler:
- (void)keyboardWasShown:(NSNotification*)aNotification{
// Resize for the stupid keyboard
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
CGRect rect = _textView.frame;
rect.size.height -= kbSize.height;
_textView.frame = rect;
CGPoint p = [_textView contentOffset];
[_textView setContentOffset:p animated:NO];
[_textView scrollRangeToVisible:NSMakeRange([_textView.text length], 0)];
}
This works dandy in portrait mode, but the view completely disapears in landscape mode. Is there a more elegant solution for dealing with this? I read apples keyboard management documentation, but it doesn't have much to offer for orientation issues.
Upvotes: 2
Views: 916
Reputation: 4108
So, my unfortunate solution is this
UIInterfaceOrientation o = [self interfaceOrientation];
if(o == UIInterfaceOrientationPortrait || o == UIInterfaceOrientationPortraitUpsideDown){
rect.size.height -= kbSize.height;
}else if(o == UIInterfaceOrientationLandscapeLeft || o == UIInterfaceOrientationLandscapeRight){
rect.size.height -= kbSize.width;
}
Which i suppose is the only way to address this. I'd still love an elegant solution though :)
Upvotes: 3