Three ways iOS develops jump scenes

Source: Internet
Author: User

Suppose a jumps to B, three ways:
1. Hold down the CTRL key, drag the control on a (for example, UIButton) to B, pop-up menu, select Modal. No need to write any code, click on a button on a to jump to B
2. Hold down the CTRL key, drag the view controller on a to B, pop-up menu, select modal, add connection lines and icons automatically between two scenes, select the icon, open storyboard Segue,identifier Enter an identifier, AAAA "for example. When a is required to jump, execute the following code:

1
[performseguewithidentifier:@sender: Self];  

3. Fully implemented in code, with the following code:

123456789
Get the Uistoryboard object first, the parameter is the file name    uistoryboard *mainstoryboard=[uistoryboard storyboardwithname:@" Mainstoryboard "Bundle:nil";    //Get Secondviewcontroller instance, parameter is storyboard ID, check View Controller, in Identity Inspector    Secondviewcontroller *second=[mainstoryboard instantiateviewcontrollerwithidentifier:@//show [self Presentviewcontroller:second Animated:yes Completion:nil];    

There are a total of 5 styles (style) switching between multiple scenes, Iphone3:
Modal (modal)-transitions to another scene to complete a task. When the task is completed, the scene is closed and returned to the original scene. Common.. The same city is the task.
Push (press in)-Creates a chain of scenes in which the user can move forward and backward.  Used to navigate the view controller. Only Navtiveviewcontroller can.
Replace (replacement, ipad only)-replaces the current scene for some ipad-specific view controllers. Ipad
Popover (pop-up box for ipad only)-a popup with arrows. Ipad
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 a new scene on the back.
Cross dissolve-old scenes fade out and new scenes fade in.
Partial Curl-The old scene opens 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-Adjusts the scene size so that it appears in portrait format.
Full screen-Adjusts the scene size so that it covers the entire screen.
Current context--Displays 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 {    //execute switch named "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 {    //off modal scene    [self dismissviewcontrolleranimated:yes completion: NIL];}

To create a modal scene switch in a purely code way:

Get references to "Mymain.storyboard" storyboards Uistoryboard *mainstoryboard =[uistoryboard storyboardwithname:@ "MyMain" Bundle:nil] ;//Instantiate the View controller identifier as "Myconfig" configviewcontroller *CONFIGVC = [Mainstoryboard instantiateviewcontrollerwithidentifier:@ "Myconfig"];//set the transition type for the view controller Configvc.modaltransitionstyle = uimodaltransitionstylecoververtical;//Setting the display style for the 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
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, how to rotate is full screen, the iphone only has this one style valid
Uimodalpresentationformsheet-the width and height are smaller than the screen size, centered, and surrounded by darkened areas. Available for ipad only
Uimodalpresentationpagesheet-In the vertical screen and the 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 areas that are not covered will darken and prevent users from tapping
Uimodalpresentationcurrentcontext--Same as the display style of the parent view

Presenting view Controller Vs presented view Controller

When we display view Controller B in modal mode in view Controller A, a acts as a presenting view controller (eject VC), and B is the presented view Controller (the VC is ejected). The official documentation suggests that the interaction between the two is done through delegate, and if you use Uiimagepickercontroller to select photos or take pictures from the system album, We can find that the Imagepickercontroller and the VC that pops up are interactive through uiimagepickercontrollerdelegate. Therefore, we use in practice, it is best to abide by this principle, in the VC that is ejected in the definition of delegate, and then in the popup VC implementation of the agent, so that it can be more convenient to achieve the interaction between the two.

Dismiss Modal Viewcontroller (Vanishing popup vc)

  Vanishing presented VC, we can do this by calling any of the following two functions

dismissmodalviewcontrolleranimated:                 //will be discarded, do not agree to continue to use Dismissviewcontrolleranimated:completion:

  who will call this vanishing presented VC this method: The right approach is "who pollutes who governs", that is, presenting VC calls the above method to cancel the display of presented VC. This has the advantage that if a VC really does not make a different choice of users may pop up different view controller, when it is no longer necessary to display the pop-up view controller, call [self Dismissmodalviewcontrolleranimated] to make it disappear without having to care about which type of view controller it specifically displays. Of course, the system is optimized here, when we call the above method in the presented VC, the system will automatically pass this message to the corresponding presenting VC, so that it can be achieved no matter who pops up, when no longer need to directly disappear the function of their own. In the application of the specific need to see the specific situation, if the presented VC needs and presenting VC has data transmission, it is recommended that the presenting VC implementation of the proxy function dismiss pop-up view controller.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.