IOS development: page Jump and pop-up mode of ViewController, iosviewcontroller

Source: Internet
Author: User

IOS development: page Jump and pop-up mode of ViewController, iosviewcontroller
ViewController page Jump

When you jump from a Controller to another Controller, there are generally two types:

1. Use UINavigationController to call pushViewController for redirection. In this way, use the stack pressure and stack exit method to manage the Controller. You can call the popViewControllerAnimated method to return the result.

PickImageViewController *ickImageViewController = [[PickImageViewController alloc] init];[self.navigationController pushViewController: ickImageViewController animated:true];[ickImageViewController release];

2. Use the presentModalViewController of UIViewController to redirect. Call the dismissModalViewControllerAnimated method to return the result.

PickImageViewController * ickImageViewController = [[PickImageViewController alloc] init]; [self presentModalViewController: ickImageViewController animated: YES]; // return [self dismissModalViewControllerAnimated: YES]; Present ViewController Modally

I. Main Purposes

The pop-up mode ViewController is a very useful technology in IOS. Some viewcontrollers provided by UIKit specifically for modal display, such as UIImagePickerController. The pop-up mode ViewController is mainly used in the following situations:

1. Collect User input information

2. Temporarily present some content

3. Temporary change of Working Mode

4. Changes in the device direction (used when two viewcontrollers are created in different directions)

5. display a new view level

In these situations, the normal execution process of the program will be temporarily interrupted. The main function is to collect or display some information.

2. Several Concepts and common settings

1. presenting view controller Vs presented view controller

When view controller B is displayed in the mode of view controller A, A acts as the presenting view controller (the VC is displayed), and B is the presented view controller (the VC is popped up ). We recommend that you use delegate to interact with each other. If you have used UIImagePickerController to select a photo or take a photo from the system album, you can find that the interaction between imagePickerController and the VC that pops up it is through UIImagePickerControllerDelegate. Therefore, we recommend that you follow this principle in actual application, define the delegate in the pop-up VC, and then implement the proxy in the pop-up VC, in this way, the interaction between the two can be easily realized.

2. Modal Presentation Styles (pop-up style)

By setting the modalPresentationStyle attribute of presenting VC, we can set the style when the View Controller is popped up. The following four styles are defined:

typedef enum {UIModalPresentationFullScreen = 0,UIModalPresentationPageSheet,UIModalPresentationFormSheet,UIModalPresentationCurrentContext,} UIModalPresentationStyle;

UIModalPresentationFullScreen indicates that the presented VC is full screen when the VC is displayed. If the wantsFullScreenLayout of the VC is set to YES, It is filled under the status bar; otherwise, it is not filled under the status bar.

UIModalPresentationPageSheet indicates that when the pop-up is VC, the height of the presented VC is the same as the current screen height, the width is the same as the screen width in portrait mode, and the remaining areas that are not covered will become darker and Prevent Users From clicking, in this pop-up mode, the portrait screen works the same as the UIModalPresentationFullScreen, while the landscape screen leaves a dark area on both sides.

In the UIModalPresentationFormSheet mode, the height and width of the presented VC are smaller than the screen size, and the presented VC is displayed in the center, with a dark area left around.

In the UIModalPresentationCurrentContext mode, the pop-up mode of presented VC is the same as that of the parent VC of presenting VC.

These four methods work on iPad, but the system always displays presented VC in UIModalPresentationFullScreen mode on iPhone and iPod touch.

3. Modal Transition Style)

By setting the modalTransitionStyle attribute of presented VC, we can set the scene to switch the animation style when the presented VC is displayed. Its definition is as follows:

typedef enum {UIModalTransitionStyleCoverVertical = 0,UIModalTransitionStyleFlipHorizontal,UIModalTransitionStyleCrossDissolve,UIModalTransitionStylePartialCurl,} UIModalTransitionStyle;

We can see four options: slide from the bottom, flip horizontally, cross-dissolve, and flip. These four styles are not limited by the device, that is, both iPhone and iPad will display the transfer effect according to our designated style.

4. Dismiss Modal ViewController (disappears the pop-up VC)

Depresented VC. We can call either of the following two functions to complete

DismissModalViewControllerAnimated: // will be deprecated. dismissViewControllerAnimated: completion:

Who will call this method to disappear presented VC: the correct method is "who pollutes who govern", that is, presenting VC calls the above method to cancel the display of presented VC. There is a benefit in doing so. If a VC does not really make different choices, different view Controllers may pop up. When the pop-up view controller is no longer needed, directly call [self dismissModalViewControllerAnimated] to make it disappear without worrying about the type of view controller it displays. Of course, the system has been optimized here. When we call the above method in presented VC, the system will automatically pass the message to the corresponding presenting VC, in this way, no matter who pops up, you can directly remove yourself when you no longer need it. The specific method used in the application depends on the specific situation. If presented VC needs to transmit data with presenting VC, we recommend that you dismiss the view controller popped up in the proxy function implemented by presenting VC.

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.