What are definesPresentationContext and providesPresentationContextTransitionStyle

前端 未结 2 1789
攒了一身酷
攒了一身酷 2020-12-13 04:06

ViewController has definesPresentationContext and providesPresentationContextTransitionStyle, but have no idea about how they work. I

相关标签:
2条回答
  • 2020-12-13 04:45

    definesPresentationContext is related to child view controllers which in storyboards are represented by Container View. So, this option influence a presentation of a new UIViewController from a container view.

    providesPresentationContextTransitionStyle is related also to child view controllers and will take effect only when definesPresentationContext is true

    0 讨论(0)
  • 2020-12-13 04:51

    Both properties are used for view controller containment, and provide child view controllers the option to override the presentation context or presentation style of the window's root view controller. For reference, here is the relevant WWDC presentation that provides an explanation of both:

    https://developer.apple.com/videos/play/wwdc2011-102/

    • definesPresentationContext is used to decide which view controller will determine the size of the presented view controller's view:

    When a view controller is presented, iOS starts with the presenting view controller and asks it if it wants to provide the presentation context. If the presenting view controller does not provide a context, then iOS asks the presenting view controller's parent view controller. iOS searches up through the view controller hierarchy until a view controller provides a presentation context. If no view controller offers to provide a context, the window's root view controller provides the presentation context.

    If a view controller returns YES, then it provides a presentation context. The portion of the window covered by the view controller's view determines the size of the presented view controller's view. The default value for this property is NO.

    • providesPresentationContextTransitionStyle is used to decide which modal presentation style should be used when presenting a child view controller:

    When a view controller’s definesPresentationContext property is YES, it can replace the transition style of the presented view controller with its own. When the value of this property to YES, the current view controller’s transition style is used instead of the style associated with the presented view controller. When the value of this property is NO, UIKit uses the transition style of the presented view controller. The default value of this property is NO.

    For complex child view controllers such as UISearchController, it's a good idea to have these set to true, the default value is false.

    0 讨论(0)
提交回复
热议问题