Swift-The jump mode of the interface

Source: Internet
Author: User
Tags instance method vars

iOS development in the interface jump in two ways, up and down jump and left and right jump.

Jump up and down _to:

    1. Let Secondviewcontroller = Secondviewcontroller ()
    2. Self. Presentviewcontroller (Secondviewcontroller, animated: True, completion: nil)

Jump up and down _back:

    1. Dismissviewcontrolleranimated (True, completion: nil)


-----------------------------------------------

-----------------------------------------------

Jump Around _to:

(Push the new view controller into Navigationcontroller, which is equivalent to the stack operation)

    1. Let Secondviewcontroller = Secondviewcontroller ()
    2. Self. navigationcontroller!. Pushviewcontroller (Secondviewcontroller, animated: true)


Jump Around _back:

(The current view controller is removed from the Navigation view controller stack to return to the upper-level interface)

( - ) Back_ to the previous level:

    1. Let Firstviewcontroller = Firstviewcontroller ()
    2. Self. Navigationcontroller?. Popviewcontrolleranimated (true)


( - ) Back_ Specify the interface:

    1. Get a view controller in the view controller
    2. Let Viewcontroller = self. Navigationcontroller?. viewcontrollers[0]
    3. Self. Navigationcontroller?. Poptoviewcontroller (Viewcontroller as! Uiviewcontroller, animated: true)


( - ) Back_ Root View:

    1. Self. Navigationcontroller?. Poptorootviewcontrolleranimated (true)

The settings for the root view need to be set in Appdelegate

 
  1. var window:uiwindow?
  2. Func application (application:uiapplication, didfinishlaunchingwithoptions launchoptions: [NSObject:  Anyobject]?) -Bool
  3. {
  4. var firstviewcontroller = Firstviewcontroller ()
  5. var Rootnavigationviewcontroller = Uinavigationcontroller (Rootviewcontroller:firstviewcontroller)
  6. self. window!. Rootviewcontroller = Rootnavigationviewcontroller
  7. return true
  8. }

OC for handwritten pages and storyboard production pages, using code for page jumps two ways.

    1. ? 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

Swift-The jump mode of the interface

Related Article

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.