Viewcontroller page jump and Popup modal _ios in IOS development

Source: Internet
Author: User

Viewcontroller page Jump
When you jump from one controller to another controller, you typically have the following 2 kinds:
1, the use of Uinavigationcontroller, call Pushviewcontroller, to jump, this use of pressure stacks and out of the stack of the way to carry out controller management. Call the Popviewcontrolleranimated method to return.

Copy Code code as follows:

Pickimageviewcontroller *ickimageviewcontroller = [[Pickimageviewcontroller alloc] init];
[Self.navigationcontroller Pushviewcontroller:ickimageviewcontroller animated:true];
[Ickimageviewcontroller release];


2, the use of Uiviewcontroller own presentmodalviewcontroller, to jump; Dismissmodalviewcontrolleranimated method can be called to return.

Copy Code code as follows:

Pickimageviewcontroller *ickimageviewcontroller = [[Pickimageviewcontroller alloc] init];
[Self Presentmodalviewcontroller:ickimageviewcontroller animated:yes];
Return
[Self dismissmodalviewcontrolleranimated:yes];


Present Viewcontroller modally


first, the main use

Pop-up modal Viewcontroller is a very useful technology for iOS, Uikit provides some viewcontroller for modal display, such as Uiimagepickercontroller. Pop-up modal Viewcontroller are mainly used in these situations:

1. Collect user input information

2. Temporarily present some content

3. Temporary change of working mode

4, the corresponding equipment direction changes (for different directions is to think two viewcontroller situation)

5. Show a new view level

These situations temporarily interrupt the normal execution process of a program, primarily by collecting or displaying some information.

two, several concepts and common settings

1, presenting view Controller Vs presented view Controller

When we show view Controller B in view Controller A, a acts as presenting view Controller (pop VC), and B is presented view Controller (is ejected VC). Official documentation suggests that the two interact through delegate, and if you've used Uiimagepickercontroller to pick photos or take pictures from your system albums, We can find that Imagepickercontroller and the VC that pops up is the interaction through uiimagepickercontrollerdelegate. Therefore, we are in practical use, it is best to adhere to this principle, in the VC is pop-up defined delegate, and then in the pop-up VC implementation of the agent, so that it can be more convenient to achieve the interaction between the two.

2, Modal presentation Styles (pop-up style)

By setting the Modalpresentationstyle property of presenting VC, we can set the style of pop-up view controller with the following four styles, which are defined as follows:

Copy Code code as follows:

typedef enum {
Uimodalpresentationfullscreen = 0,
Uimodalpresentationpagesheet,
Uimodalpresentationformsheet,
Uimodalpresentationcurrentcontext,
} Uimodalpresentationstyle;

Uimodalpresentationfullscreen on behalf of VC, presented VC full screen, if the VC wantsfullscreenlayout set to Yes, it will be populated below the status bar, Otherwise, it will not be populated under the status bar.

Uimodalpresentationpagesheet on behalf of Pop-up VC, presented VC height and the current screen height is the same, width and vertical screen mode under the same width, the remaining not covered areas will darken and prevent users click, this pop-up mode, When the vertical screen is the same as the uimodalpresentationfullscreen effect, the horizontal screen will leave a darkened area on both sides.

Uimodalpresentationformsheet this mode, presented VC height and width will be smaller than screen size, presented VC center, surrounded by darkened areas.

Uimodalpresentationcurrentcontext this mode, presented VC pop-up way and presenting VC's parent VC the same way.

These four ways are all available on the ipad, but the system is always uimodalpresentationfullscreen mode on the iphone and ipod Touch to show presented VC.

3, Modal Transition style (pop-up animation style)

By setting the presented VC Modaltransitionstyle Properties, we can set the pop-up presented VC when the scene toggle animation style, its definition is as follows:
Copy Code code as follows:

typedef enum {
uimodaltransitionstylecoververtical = 0,
Uimodaltransitionstylefliphorizontal,
Uimodaltransitionstylecrossdissolve,
Uimodaltransitionstylepartialcurl,
} Uimodaltransitionstyle;

We can see that there are four styles that are available to slide in from the bottom, horizontally flip into, cross dissolve and flip. These four styles are not limited by the device, that is, both the iphone and the ipad will show the transitions according to the style we specify.

4, Dismiss Modal Viewcontroller (vc disappearing pop-up)

Disappearing presented VC, we can do this by calling any of the following two functions
Copy Code code as follows:

Dismissmodalviewcontrolleranimated://will be discarded, not in favor of continued use
Dismissviewcontrolleranimated:completion:

Who to call this disappears presented VC this method: The correct way is "who pollution who governs", namely presenting VC call above method to cancel presented VC display. Doing so has a benefit, if a VC really does not make different choices may pop different view controller, when no longer need to show the pop-up view controller, call directly [self Dismissmodalviewcontrolleranimated] can make it disappear without having to worry about what kind of view controller it shows. Of course, the system here to do the optimization, when we call the presented VC in the above method, the system will automatically pass this message to the corresponding presenting VC, this can be achieved regardless of who pops up their own, when no longer needed when the immediate disappearance of their own function. In the application of specific to see the specific situation, if presented VC needs and presenting VC have data transmission, the proposed presenting VC implementation of the proxy function dismiss pop-up view controller.

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.