Override horizontally compact environment behaviour for modalPresentationStyle of '.formSheet' - ios

When presenting a UIViewController with modalPresentationStyle = .formSheet, Horizontally compact environment behaves same as UIModalPresentationStyle.fullScreen
According to Apple's Documentation
UIModalPresentationStyle.formSheet.
In a horizontally regular environment, the view controller is sized so that its content area is smaller than the screen size and a dimming view is placed underneath the content. If the device is in a landscape orientation and the keyboard is visible, the position of the view is adjusted upward so that the view remains visible. All uncovered areas are dimmed to prevent the user from interacting with them.
In a horizontally compact environment, this option behaves the same as UIModalPresentationStyle.fullScreen.
It looks like Apple Maps settings screen is presented with modalPresentationStyle = .formSheet but for Horizontally compact environment, it doesn't cover fullscreen but it covers only half the screen.
How can we override the behaviour for Horizontally Compact environment so that it covers only the half of the screen?

Related

Popover view with arrow on iPhone

I need to present a UI in a popover with arrow which has few controls that works on both iPhone and iPad. I am not sure what is the best way to do this that works correctly with Autolayout and resizing. Let's say I have a UIButton, UISlider, UIButton, UISlider in that order which are equally spaced vertically in the view, how do I set Autolayout constraints and present the view as popover that adapts to resizing? There are essentially two questions here -- how to display a view as popover with arrow and how to use autolayout to adapt to presentation size.

iOS: formSheet modalPresentationStyle view controller size shrinked

I'm presenting a view controller with modalPresentationStyle set to formSheet, then I noticed the size of the view controller displayed isn't the same as how it's designed, it looks like iOS tries to shrink it to be smaller.
The doc says:
In a horizontally regular environment, the view controller is sized so that its content area is smaller than the screen size and a dimming view is placed underneath the content.
It's not clear to me how the resizing is done (ie. "the view controller is sized so that..."), I have a button with left/right edge margin, which isn't preserved. Is this how iOS works? Do I need to set preferredContentSize if I want to force it to have certain size?
Thanks!

"Present as Popover" segues and view size

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?
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
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.

How do I resize a UINavigationController's contents when a UISplitViewController rotates to portrait

I have a UISplitViewController that uses a navigation controller for its master (left) pane. When it rotates to portrait, this navigation controller is represented within a UIPopoverController. I'm noticing that the UITableView that is being shown in the navigation controller's current view does not resize when the app rotates to portrait. Namely, I see the popover at full height (about 1024 pixels), but the table is black along the bottom, seemingly still about 700 pixels in height.
How do I adjust the navigation and/or table view height properly?
This question is old, but for future reference, the documented way of handling this is to set the contentSizeForViewInPopover property on the view controller. You can also use the popoverContentSize property of the popover controller. See the dev docs for details.

iPad - General Network->What is the UI control?

In the below image, what is the UI control used to create the "Other Network" dialog? We need to create a similar non-full-screen popup.
I think what you're looking for is a UIModalPresentationFormSheet.
From Apple's UIViewController documentation reference
UIModalPresentationFormSheet
The width and height of the presented view are smaller than those of the screen and the view is centered on the screen. If the device is in a landscape orientation and the keyboard is visible, the position of the view is adjusted upward so that the view remains visible. All uncovered areas are dimmed to prevent the user from interacting with them.
Available in iOS 3.2 and later.
Declared in UIViewController.h.
See this article for an example Display a view using modalPresentationStyle
It should be a view controller presented modally using UIModalPresentationFormSheet as its modalPresentationStyle.

Resources