Logicsaurus Rex Logicsaurus Rex - 4 months ago 13x
iOS Question

AutoLayout constraints and UIPopoverPresentationController

AutoLayout seems to be battling me every step of the way with a view's size.

I have a view controller that I use for user input, and AutoLayout seems unshakeably determined to make my view 667 pixels high.

I've played with many variants of the layout settings, many content hugging and compression resistance combinations, and no matter what I do, AutoLayout finds a way to stretch the view to 667 pixels high.

I use Reveal, an app that shows layout frames, constraints, etc. (revealapp.com)
and it is showing me that the UIPopoverPresentationController is adding its own autoresizing constraints.

Here's how my view should approximately look when presented...

enter image description here

Note that even though I have the "Accept" UIButton set to 30 pixels high with a 1000 priority, AutoLayout is still stretching it to meet it's weird 667 pixel high requirement.

When I run the app, here's how my popover looks...

enter image description here

and when I have Reveal examine the running app, and I narrow it down to the popover, this is what Reveal shows...

enter image description here

enter image description here

Note the UIPopoverPresentationController itself has these constraints on it.

How can I control the constraints being put in by the UIPopoverPresentationController ??


Try using boundingRectWithSize(_:options:attributes:context:) of NSString to determine what the height of your labels is going to be.

Once you've done that, you can predict what the size of your popover is going to be by adding in whatever extra height your labels create. You can use that to set the preferredContentSize property of the view controller you are presenting.