“Present as Popover” segues and view size

强颜欢笑 提交于 2019-12-12 11:29:50

问题


Can anyone point to any guidance/documentation on how items should be placed in a view controller that will be displayed as a popover so that the components are appropriately positioned with auto layout?

Specifically: I'm working in Xcode 8.3 with the new "Present as Popover" segue, with the new "universal" storyboards. I add a view controller and then a popover segue to that view controller. When it is displayed, I see that roughly the top-left quadrant of the view controller is displayed as a popover, but that no auto layout appears to be taking place as far as I can see to accommodate the slightly different sizes of an iPad popover vs "full screen" behaviour on the different sized iPhones -- so in effect, a slightly different section of the view controller is visible depending on the device.

I assume this isn't really how things are supposed to work, and the whole raison d'être of the universal popover segue is to appropriately fit things to the popover size via auto layout? So can anyone shed some light on what I'm doing wrong or how popups are supposed to work with respect to auto layout?


回答1:


Something to watch for with popovers is that on devices like the iPad, the size class for the popover is not the same as the controller which raises it.

You will probably find that the size class goes from regular width to compact width when you use a popover on an iPad. If you have layout coded to regular width for your popover content, then it will not work in the popover.

The size of the popover itself comes from the content size properties for the controller presented. You can set this size explicitly in the attribute inspector for the view controller or in code. See: How to present popover properly in iOS 8




回答2:


To make the elements display correctly on screen, change the size class control to Any-Any (near the layout toolbar at the bottom of the Interface Builder canvas) before adding elements in the Storyboard in the View Controller that will act as a popover.



来源:https://stackoverflow.com/questions/29674862/present-as-popover-segues-and-view-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!