8

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.

static0886
  • 784
  • 9
  • 25
  • I'm having the converse problem; on iPhone X, I'm trying to keep my popover in the safe area (because somehow the new navigation bar overlaps my popup, which it's never done on previous iPhones), but it completely ignores even positive-valued `popooverLayoutMargins`. I hope you receive an answer to this. – Jamie Birch Oct 02 '17 at 17:21
  • 2
    This bug has been present for years now. The UIPopoverPresentationController was introduced with iOS 8, and I think this property actually never worked. I think your best bet is to calculate the preferredContentSize and set it on the view controller that is being presented in the popover. – Lukas Petr Oct 28 '17 at 12:55

0 Answers0