My popovers are sizing incorrectly in iOS 7. The height is working fine, but the width is not getting set at all. The popover has a very skinny width, no matter what I set it to. It still works in iOS 6 but breaks in iOS 7. Is there something new I need to do with popovers in 7 that I'm missing?
Here's the code that works in iOS 6 and not iOS 7:
self.mediaPicker = [[UIImagePickerController alloc] init];
self.mediaPicker.contentSizeForViewInPopover = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);
self.cameraPickerPopover = [[UIPopoverController alloc] initWithContentViewController:self.mediaPicker];
self.cameraPickerPopover.popoverContentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);
self.cameraPickerPopover.delegate = self;
[self.cameraPickerPopover presentPopoverFromRect:self.toolbar.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:animated];
I found out contentSizeForeViewInPopover is deprecated in iOS 7 so I updated the code as follows and it's still not working:
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
self.mediaPicker.contentSizeForViewInPopover = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);
} else {
self.mediaPicker.preferredContentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);
}
The answer provided here
How to change the size width of UIImagePickerController on iPad?
is correct, except that for iOS 7, the contentSizeForViewInPopover property should be replaced by the preferredContentSize property.
The UIImagePickerController's delegate implements the UIImagePickerControllerDelegate and the UINavigationControllerDelegate protocols.
Adding the following method in the delegate implementation solves the issue in iOS 7 for me :
- (void)navigationController:(UINavigationController*)navigationController willShowViewController:(UIViewController*)viewController animated:(BOOL)animated
{
if (SYSTEM_VERSION_GREATER_THAN(@"7.0"))
viewController.preferredContentSize = CGSizeMake(800,800);
else
viewController.contentSizeForViewInPopover = CGSizeMake(800, 800);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With