? Handwritten pages:
var vc = ViewController() self.presentViewController(vc, animated: true, completion: nil)
? Storyboard Production Page
var sb = UIStoryboard(name: "Main", bundle:nil) var vc = sb.instantiateViewControllerWithIdentifier("VC") as ViewController//VC为该界面storyboardID,Main.storyboard中选中该界面View,Identifier inspector中修改self.presentViewController(vc, animated: true, completion: nil)
self.performSegueWithIdentifier("VC", sender: nil)
A total of 5 styles (style) switching between multiple scenes: Modal (modal)--transition to another scene to complete a task. When the task is completed, the scene is closed and returned to the original scene.
Push (press in)-Create a chain of scenes in which users can move forward and backward. Used to navigate the view controller.
Replace (replacement, ipad only)--Replace the current scene for some ipad-specific view controllers.
Popover (pop-up box, only for ipad)--A pop-up box with arrows.
Custome (Custom)--Customize transitions between scenes by compiling.
A transition type (Transition) is an animation that plays when you switch from one scene to another. There are 4 options: Cover Vertical--The new scene moves from the bottom up, gradually covering the old scene.
Flip Horizontal--The view is flipped horizontally to show the new scene on the back.
Cross Dissolve-old scenes fade out and new scenes fade in.
Partial Curl--The old scene opened like a page, showing the new scene below.
In the ipad app, there is also an extra presentation attribute that determines how the modal view is displayed on the screen. There are 4 kinds of display styles:
Form Sheet (Form)--Adjusts the scene to be smaller than the screen (regardless of orientation) and displays the original scene behind the current scene, which is almost equivalent to being displayed in an ipad window.
Page Sheet (page)--Adjust the scene size so that it appears in portrait format. Full
Screen (fullscreen)--Adjust the scene size so that it covers the entire screen.
Current context--Display the scene in the same way as the original scene.
To use the switch to another scene defined in the storyboard, but do not want to automatically trigger the switch, you can use the Uiviewcontroller instance method Performseguewithidentifier:sender. When the method is called, the switchover starts and transitions occur. The parameter sender should be set to start the Toggled object. This allows you to determine which object initiated the switchover during the switchover.
- (IBAction)toConfigHandler:(id)sender { //执行名为"toConfig"的切换 [self performSegueWithIdentifier:@"toConfig" sender:self];}
Calling Uiviewcontroller's method dismissviewcontrolleranimated:completion, you can close the current modal view and return to the original scene. Completion is an optional parameter that specifies the block of code that will be executed when the transition is complete.
- (IBAction)returnToMainHandler:(id)sender { //关闭模态场景 [self dismissViewControllerAnimated:YES completion:nil];}
To create a modal scene switch in a purely code way:
//get "Mymain.storyboard" Storyboard references Uistoryboard *mainstoryboard =[uistoryboard storyboardwithname:@ "Mymain" bundle:nil]; //instantiate identifier as "Myconfig" View Controller Configviewcontroller *CONFIGVC = [Mainstoryboard Instantiateviewcontrollerwithidentifier:@ "Myconfig"]; //set the transition type for the view controller Configvc.modaltransitionstyle = uimodaltransitionstylecoververtical; //set display style for view controller Configvc.modalpresentationstyle = uimodalpresentationfullscreen; //display view [self PRESENTVIEWCONTROLLER:CONFIGVC Animated:yes completion:nil];
The Modaltransitionstyle (Transition type) property of the view has the following enumeration values: Uimodaltransitionstylecoververtical--default value, overriding from bottom up
Uimodaltransitionstylefliphorizontal--Flip horizontally
Uimodaltransitionstylecrossdissolve--Fade in and fade
Uimodaltransitionstylepartialcurl--open like a page to show the view below
The Modalpresentationstyle (display style) property of the view has the following enumeration values: Uimodalpresentationfullscreen--default value, how to rotate is full screen, iphone only this one style valid
Uimodalpresentationformsheet--the width and height are smaller than the screen size, centered, and surrounded by darkened areas. Only available for
Ipaduimodalpresentationpagesheet--as in the vertical screen and uimodalpresentationfullscreen performance, the horizontal screen height is the same as the current screen height, width and vertical screen mode screen width is the same, the remaining area will be dimmed and prevent users from clicking
Uimodalpresentationcurrentcontext--Same as the display style of the parent view