There are two ways to implement a view controller to the screen: embed it in a container view controller or directly render it. The container view Controller provides a primary navigation function for an application, but the present view controller is also an important navigation tool. You can directly use presentation to display a new view controller at the top of the current view controller. Typically, when you want to implement the modal interface directly present the view controller, but you can also use them for other purposes.
Support for rendering view controllers is built into the class Uiviewcontroller and is valid for all view controller objects. You can present any view controller on any other view controller, although Uikit may change the requirements for different view controllers. Present A view controller establishes a relationship between the original view controller (known as the presenting view Controller) and the new view controller that will be exhibited (known as the presented view controller). This relationship forms part of the view controller hierarchy and remains in the appropriate position until the presented view controller is dismiss.
Show (Presentation) and over (Transition) processes
Rendering a view controller is a quick and easy way to animate new content onto the screen. The presentation mechanism is built into the uikit, allowing you to display a new view controller using either built-in or custom animation (animations). The built-in presentations and animations only require very little code, because Uikit handles all the work for you. You can also create custom presentations and animations, and you just need a little extra effort to use them in any of your view controllers.
You can start the presentation of a view controller by encoding or by using segues. Segues is the simplest way to start presentations if you are aware of the navigation capabilities of your application at design time. For more dynamic interfaces, or in case there is no dedicated control to start segue, then use the Uiviewcontroller method to render your view controller.
Presentation Styles
The presentation style of a view controller determines its display on the screen. UIKit defines a number of standard presentation styles, a specific display and intent. You can also customize your own presentation style. When designing your app, choose the most appropriate presentation style for the things you want to do, and specify the appropriate constants for the Modalpresentationsstyle property of the view controller you want to render.
Full-screen Presentation Style
Full-screen presentation styles cover the entire screen, preventing the view controller from interacting with the underlying content. In a horizontal regular environment, only one of the full-screen style views completely covers the underlying content. If the full-screen view contains darkened or transparent portions, allow the corresponding portion of the underlying view controller to be displayed through the full-screen view. In a horizontal compact environment, full-screen presentation automatically adapts to the Uimodalpresentationfullscreen style, overwriting content that is located below the top-level view.
Figure 8-1 Using UIModalPresentationFullScreen
, UIModalPresentationPageSheet
, andUIModalPresentationFormSheet
Styles,To illustrate the display of presentations in a horizontal regular environment. In the diagram, the Green View controller is displayed in the upper-left corner, and the Blue View controller is displayed in the upper-right corner, and each presentation style is displayed below. For some presentation styles, UIKit Inserts a dim view between the contents of the two view controllers.
Figure 8-1 Full Screen presentation styles
-Note: When using Uimodalpresentationfullscreen to render a view controller, UIKit usually removes the view controller under the current view after the toggle action (transition animations) is complete. You can UIModalPresentationOverFullScreen
prevent these view controllers from being removed by specifying a style. When the presented view controller has transparent areas, you may use this style, which allows the bottom content to be displayed through the transparent area.
When using one of the full-screen presentation styles, the view controller must cover the entire screen itself when it starts presentation. If the presenting view controller does not cover the entire screen, then Uikit wakes up the view controller hierarchy until it finds a working view controller. If you do not find an intermediate view controller to populate the screen, Uikit uses the window's root view to populate it.
The Popover style
uimodalpresentationpopover
  style displays a view controller in a popover view. Popovers is useful for displaying additional information or listing related items for a Focus object or a selected object. In a horizontal regular environment, the Popovers view covers only a portion of the screen, as shown in 8-2. In a horizontal compact environment, the popovers default adaptation uimodalpresentationoverfullscreen
  presentation style. Tapping the screen outside of the PopOver view automatically dismiss the PopOver view.
Figure 8-2 the PopOver presentation style
Because in a horizontal compact environment, Popovers automatically adapts to full-screen presentations, you usually need to modify your PopOver code to handle this adaptation. In Full-screen mode, you need a way to dismiss a presented popover. You can do this by adding a button, embedding the popover into a dismissible container view controller, or changing its own adaptation behavior. For more tips on how to configure a Popover presentation, see presenting a View Controller in a Popover.
The current Context Styles
The UIModalPresentationCurrentContext
style overrides a specified view controller in your interface. When using the contextual style, you specify the view you want to overwrite by setting its Definespresentationcontext property to Yes. Figure 8-3 illustrates an example of a current context presentation that only covers a sub-view controller of the split view controller.
Figure 8-3 The current context presentation style
-Note: When the uimodalpresentationfullscreen style is used to render a view controller, the Uikit automatically removes the underlying view after the toggle action is complete. You can UIModalPresentationOverCurrentContext
Prevent these views from being removed by specifying a style. When the presented view controller has transparent areas, you may use this style to let the content below show through the transparent area.
During presentation, the view controller defines the presentation context, or you can define a transition animation to use. Typically, the UIKit on-screen Animates view controller uses the value of the Modaltransitionstyle property of the presented view Controller. If the presentation context View controller is providespresentationcontexttransitionstyle
is set to Yes, then Uikit uses this view controller's
When switching to a horizontal compact environment, the current context styles automatically adapt UIModalPresentationFullScreen
to the style. To change this behavior, use an adaptable presentation delegate to specify a different presentation style or view controller.
Custom Presentation Styles
UIModalPresentationCustom
Style lets you use your custom style to render a view controller. Creating a custom style involves sub-classUIPresentationController
, use its method to animate any custom view to the screen, setting the size and position for the presented view Controller. Any adaptability that occurs is also handled because the Traits,presentation view controller for the presented view controller is changed. For more information on how to define a custom presentation controller, see Creating Custom presentations.
Transition Styles
。。。 Not to be continued
iOS View Controller Programming Guide---rendering a view controller