As the title suggests, whatever values I provide for the popoverLayoutMargins, nothing seems to happen.
I am attempting to display a popover menu anchored to a UIButton. All works fine except that I would like to have the popover to expand the width of the screen.
I have tried playing with the preferredContentSize
of the presented UIViewController
.
The problem is I cannot make the popover expand all the way to the edges of the screen.
According to the documentation I find that:
The default edge insets are 10 points along each edge
And changing that programatically produces no effect. To verify this I am using the Xcode's view debugger.
Window:
<UIWindow: 0x7fc96cd02c50; frame = (0 0; 375 667); gestureRecognizers = <NSArray: 0x60000025d580>; layer = <UIWindowLayer: 0x600000039140>>
UIPopoverView
<_UIPopoverView: 0x7fc96cf227a0; frame = (10 101; 355 57); layer = <CALayer: 0x61000023f760>>
Note the width of the popover is exactly 10+10 points smaller than the window width
I'm attempting to change the margins using:
menu.popoverPresentationController?.popoverLayoutMargins = UIEdgeInsets(top: 0, left: -90, bottom: 0, right: -90)
I'm tried doing that using both before presenting the viewController AND after. That's because the UIPopoverPresentationController documentation states that
Configuring the popover presentation controller after calling present(_:animated:completion:) might seem counter-intuitive but UIKit does not create a presentation controller until after you initiate a presentation. In addition, UIKit must wait until the next update cycle to display new content onscreen anyway. That delay gives you time to configure the presentation controller for your popover.