Do you really know about UIViewController redirection ?, Uiviewcontroller jump

Source: Internet
Author: User

Do you really know about UIViewController redirection ?, Uiviewcontroller jump

I. UIViewController modal jump

// Display the modal view-(void) presentViewController :( UIViewController *) viewControllerToPresent animated: (BOOL) flag completion :( void (^ _ nullable) (void) completion (5_0 ); // disable the modal view-(void) dismissViewControllerAnimated: (BOOL) flag completion: (void (^ _ nullable) (void) completion NS_AVAILABLE_IOS (5_0 ); // only to IOS6-(void) presentModalViewController :( UIViewController *) modalViewController animated :( BOOL) animated updated (2_0, 6_0); // only to IOS6-(void) Updated :( BOOL) animated NS_DEPRECATED_IOS (2_0, 6_0 );

Knowledge Point 1:

A: In the official documentation, we recommend that you use delegate to implement interaction between the two. For example, you can use UIImagePickerController to select a photo or take a photo from the system album. The interaction between imagePickerController and the VC that pops up it is realized through UIImagePickerControllerDelegate.

B: The read-only attribute in the Controller: presentedViewController and presentingViewController. They are the controllers under the present and the controllers under the presenting respectively.

C: Modal effect: by default, the new controller is drilled up from the bottom of the screen until the previous controller is covered. However, you can customize the transition field to change the animation, size, location, and whether to remove the previous view. This effect can be used to simulate the popopover pop-up box unique to the ipad.

D: by default, its implementation process is to remove the view of the controller before the jump, and display the view of the new controller, but the controller is not released before the jump, it is strongly referenced. Different from the push of the navigation controller.

E: Use dismissViewControllerAnimated to return

Knowledge Point 2: for example, the current A controller uses the mode to jump to another B Controller

1. current A controller, jump to the Code RecipeAddViewController * addController = [[RecipeAddViewController alloc] init]; addController. modalPresentationStyle = UIModalPresentationFullScreen; addController. transitionStyle = UIModalTransitionStyleCoverVertical; [self presentViewController: addController animated: YES completion: nil]; 2. return to the current A controller. Add the return code [self dismissViewControllerAnimated: YES completion: NULL] to the B controller that you just jumped to.

Knowledge Point 3: two important enumerated objects

// The animation style typedef NS_ENUM (NSInteger, UIModalTransitionStyle) {UIModalTransitionStyleCoverVertical = 0, // slide from the bottom into timeline, // flip horizontally into UIModalTransitionStyleCrossDissolve, // cross-Dissolve javasns_enum_available_ios (3_2), // flip}; // pop-up style typedef NS_ENUM (NSInteger, UIModalPresentationStyle) {UIModalPresentationFullScreen = 0, // indicates that the VC is displayed, full Screen UIModalPresentationPageSheet NS_ENUM_AVAILABLE_IOS (3_2). // The height of the VC is the same as that of the current screen. The width is the same as that of the screen in portrait mode, the remaining areas that are not covered will become dark and Prevent Users From clicking. in this pop-up mode, the portrait screen is the same as the UIModalPresentationFullScreen, and the two sides of the landscape screen are dimmed; UIModalPresentationFormSheet NS_ENUM_AVAILABLE_IOS (3_2 ), // The height and width of the VC are smaller than the screen size. The VC is displayed in the center, and the hidden area is left around. UIModalPresentationCurrentContext NS_ENUM_AVAILABLE_IOS (3_2 ), // The pop-up mode of VC is the same as that of the parent VC of the pop-up VC. // The Custom transition mode requires proxy Implementation of UIModalPresentationCustom NS_ENUM_AVAILABLE_IOS (7_0), UIModalPresentationOverFullScreen limit ), UIModalPresentationOverCurrentContext resume (8_0), UIModalPresentationPopover resume (8_0), // tell the Presentation controller to ignore the compact environment and continue using the Presentation style UIModalPresentationNone resume (7_0) =-1 ,};

Ii. Navigation controller UINavigationController jump

// Launch interface-(void) pushViewController :( UIViewController *) viewController animated :( BOOL) animated; // return to remove the Controller on the top of the stack-(nullable UIViewController *) popViewControllerAnimated :( BOOL) animated; // specify the name of the sub-controller to which the response is redirected. Return to the specified sub-controller (nullable NSArray <__kindof UIViewController *> *) popToViewController :( UIViewController *) viewController animated :( BOOL) animated; // return to the top-level to return to the root controller (stack bottom Controller)-(nullable NSArray <__kindof UIViewController *> *) popToRootViewControllerAnimated :( BOOL) animated;

Knowledge Point 1: popToViewController usage

[Self. navigationController popToViewController: [self. navigationController. viewControllers objectAtIndex: 2] animated: YES]; or UIViewController * popCtl; for (UIViewController * ctl in self. navigationController. viewControllers) {if ([ctl isKindOfClass: [MyViewController class]) {popCtl = ctl; break ;}} if (popCtl) {[self. navigationController popToViewController: popCtl animated: YES];}

Knowledge Point 2: iOS solves the problem of pushViewController failure caused by the use of modal views

By default, the modal view slides out from the bottom of the interface and occupies the entire interface. A different interface is displayed for a while until the user completes an operation. The modal view completes independent tasks related to the main function of the program, and is especially suitable for the multi-level subtasks lacking in the main function interface. For example, the mode view when writing a new mail.

For example:
When the logon interface is used as the modal view. when we leave the current field, use presentViewController to bring up the logon interface .. the jump between views in the modal view on the logon interface fails. this is because the modal view is actually different from the new view of the navigation controller. Only after the view is processed can it be returned to the original view. A modal view is equivalent to a dead-end access and must return the original path, that is, the page Jump cannot be performed in the modal view.

That is, the navigation controller cannot be obtained in the modal mode. The result is as follows: self. navigationController is empty. How to make self in the mode. navigationController is easy to use. You only need to encapsulate the View Controller Into A navigationController, and this mode is used only as the rootViewController of the navigationController.

UINavigationController * navi = [[UINavigationController alloc] initWithRootViewController: loginVC];

[Self. navigationController presentViewController: navi animated: YES completion: nil];

Then, in this mode, the navigation controller we passed in can be completed by the jump of the View Graph, as shown in the Code; then: self. navigationController exists. if you want to jump back, you can use pushViewController. Because a layer of navigationController is encapsulated, The 'Mode' can be hidden by the navigation bar.

Exit the modal View:

[Self dismissViewControllerAnimated: YES completion: nil];

Knowledge Point 3: solve the problem of using [self. navigationController pushViewController: VC animated: YES]; push lagging

UIViewController * vc = [UIViewController new]; [self. navigationController pushViewController: vc animated: YES]; The above code will be stuck on the launch interface solution: UIViewController * vc = [UIViewController new]; vc. view. backgroundColor = [color of the controller View you want when UIColor is released]

 

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.