I have a view which I would like to fill up the entire screen between a UIToolbar at the top and the keyboard at the bottom. I am listening for UIKeyboardWillShowNotification messages to detect when the keyboard appears and using the following to adjust the view:
- (void)keyboardWillShow:(NSNotification*)notification {
NSDictionary* userInfo = [notification userInfo];
CGSize keyboardSize = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
[UIView animateWithDuration:0.3f animations:^{
subview.frame = CGRectMake(subview.frame.origin.x, subview.frame.origin.y, self.view.frame.size.width - 40, self.view.frame.size.height - 62 - keyboardSize.height - 20);
}];
}
This works fine in portrait mode but in landscape the view is all over the place. I have tried switching the width/height when the device is in landscape mode to no avail.
I know this is basic stuff but I’ve always struggled to understand how to adjust a view correctly for landscape mode.
You should use
CGSize screenSize=[[UIScreen mainScreen] bounds].size;Then replace,
with this line:
I just tried and it worked on both directions, hope it helps!