Reputation: 1087
I'm working on an app that has some forms that are contained within a popover. My problem is that when I click on any text entry field and the keyboard appears, the popover shrinks to the upper left hand corner of the screen (0,0) and you can't see the fields you are entering into. When you click the hide keyboard button, the popover returns to its normal size and position.
Is there any way to prevent popover resizing when the keyboard appears?
Here are screen shots in case my description is inadequate.
edit: Here is the code for how the popover is presented on the screen:
(void)displayPopoverForOrientation:(UIInterfaceOrientation)orientation {
if ([Utilities getAppDelegate].menuPopover) {
CGRect rect = CGRectMake(0, 0, 0, 0);
if (orientation == UIInterfaceOrientationLandscapeLeft ||
orientation == UIInterfaceOrientationLandscapeRight) {
if (self.currentPopover == RESERVATIONS_POPOVER) {
rect = CGRectMake(365, 0, 0, 0);
} else if (self.currentPopover == ACCOUNT_POPOVER) {
rect = CGRectMake(600, 0, 0, 0);
} else if (self.currentPopover == RESORTS_POPOVER) {
rect = CGRectMake(0, 0, 0, 0);
}
}
[[Utilities getAppDelegate].menuPopover presentPopoverFromRect:rect
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
}
}
Inside the popover is a separate view controller with the layout setup in a xib. Feel free to ask any questions, I'm fairly new to iOS and Objective C, but I'm not new to coding so I'll do my best to clarify.
edit 2: I've found that this only occurs in iOS 5. In older versions of iOS, the popover merely collapses vertically until there is enough room for the keyboard. Any ideas about about why this behavior has changed in iOS 5?
Upvotes: 4
Views: 6541
Reputation: 2614
Actually it is very possible!... This is to do with the auto-Resizing that is ticked by default in IB:
I posted this on an another forum with similar question,.. The solution for me was to:
1) Go into the designer by 2) Opening the XIB ViewController that is causing the problem (i.e. the PopOver one). 3) Click to select it's VIEW. 4) Uncheck "AutoResizeSubviews" 5) When loading the PopOver in code, make sure you do: 6) Your_Popup_Window.popoverContentSize = Your_ViewController.view.bounds.size;
I hope this helps.
Kind Regards Heider Sati
Upvotes: 2
Reputation: 56
It's not possible to prevent the popover from changing shape when the keyboard appears. According to Apple's UIPopoverController docs:
The size you specify is just the preferred size for the popover’s view. The actual size may be altered to ensure that the popover fits on the screen and does not collide with the keyboard.
IOS will try to move it out of the way, but it may not be possible, depending on where you are presenting it from. For best results, present it from a bar button or from inside a scroll view (UITableView is ok), and design your UI so the popover is not too large (if the popover covers most of the screen, perhaps you should consider a segue to a modal view or similar). I found I needed to draw some diagrams so I could understand the layout better before I could get a solution that worked in all cases.
Upvotes: 2