iOS Developer Library — Prerelease

Developer

UIKit Framework Reference UIAdaptivePresentationControllerDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

UIAdaptivePresentationControllerDelegate

An object that conforms to the UIAdaptivePresentationControllerDelegate protocol works with a presentation controller to determine how to respond to size changes in your app. The delegate object is consulted only for presentations that use the UIModalPresentationFormSheet, UIModalPresentationPopover, or UIModalPresentationCustom style. Your delegate can suggest both a new full-screen presentation style and an entirely new view controller for the content.

After implementing an object that conforms to this protocol, assign that object to the delegate property of an appropriate UIPresentationController object. For more information about using the delegate to respond to size class changes, see UIPresentationController Class Reference.

  • Asks the delegate for the new presentation style to use.

    Declaration

    Swift

    optional func adaptivePresentationStyleForPresentationController(_ controller: UIPresentationController) -> UIModalPresentationStyle

    Objective-C

    - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController * _Nonnull)controller

    Parameters

    controller

    The presentation controller that is managing the size change. Use this object to retrieve the view controllers involved in the presentation.

    Return Value

    The new presentation style, which must be either UIModalPresentationFullScreen or UIModalPresentationOverFullScreen.

    Discussion

    The presentation controller calls this method when the app is about to change to a horizontally compact environment. Use this method to indicate that you want the presented view controller to transition to one of the full-screen presentation styles.

    If you do not implement this method or return any style other than UIModalPresentationFullScreen or UIModalPresentationOverFullScreen, the presentation controller adjusts the presentation style to the UIModalPresentationFullScreen style.

    Availability

    Available in iOS 8.0 and later.

  • Asks the delegate for the view controller to display when adapting to the specified presentation style.

    Declaration

    Swift

    optional func presentationController(_ controller: UIPresentationController, viewControllerForAdaptivePresentationStyle style: UIModalPresentationStyle) -> UIViewController?

    Objective-C

    - (UIViewController * _Nullable)presentationController:(UIPresentationController * _Nonnull)controller viewControllerForAdaptivePresentationStyle:(UIModalPresentationStyle)style

    Parameters

    controller

    The presentation controller that is managing the size class change.

    style

    The new presentation style that is about to be employed to display the view controller.

    Return Value

    The view controller to display in place of the existing presented view controller.

    Discussion

    When a size class change causes a change to the underlying presentation style, the presentation controller calls this method to ask for the view controller to display in that new style. This method is your opportunity to replace the current view controller with one that is better suited for the new presentation style. For example, you might use this method to insert a navigation controller into your view hierarchy to facilitate pushing new view controllers more easily in the compact environment. In that instance, you would return a navigation controller whose root view controller is the currently presented view controller. You could also return an entirely different view controller if you prefer.

    If you do not implement this method or your implementation returns nil, the presentation controller uses its existing presented view controller.

    Availability

    Available in iOS 8.0 and later.