In iOS 17, I am having an issue where UIPopoverPresentationControllers are not retaining the preferred size of the UIViewController they contain.
The following method uses a UIPopoverPresentationController popoverVC
to display a UIViewController contentVC
from a UIView view
anchor location frame
.
+ (void) showDialogiPad:(UIViewController *)contentVC
fromPresentingVC:(UIViewController *)presentingVC
inView:(UIView *)view
atFrame:(CGRect)frame
withDirection:(UIPopoverArrowDirection)direction {
// Set content view controller size
contentVC.preferredContentSize = contentVC.view.frame.size;
// Choose the presentation style in which the content is
// displayed in a popover view
contentVC.modalPresentationStyle = UIModalPresentationPopover;
// Get a popover presentation controller
UIPopoverPresentationController *popoverVC =
contentVC.popoverPresentationController;
// Set the popover size and anchor location
contentVC.popoverPresentationController.sourceRect = frame;
contentVC.popoverPresentationController.sourceView = view;
// Set the arrow direction for the popover
popoverVC.permittedArrowDirections = direction;
// Present the popover presentation controller
[presentingVC presentViewController:contentVC animated:YES completion:nil];
}
Prior to iOS 17, the code displayed the popover as expected as shown here:
The issue now however is since the update to iOS 17, the popover is now squashed and displayed as:
A few observations:
- The popover dialog actually displays properly the first time you open it. Every subsequent time you open it, it is squashed.
- When I comment out the line that sets the preferredContentSize, the popover opens at the max size every time - so it shows all the content but it is not set to the size I want it to be.
- If I leave preferredContentSize as is but change modalPresentationStyle to UIModalPresentationFormSheet, the size of the popover is correct but the popover always presents in the middle of the screen.