iOS development-View controller left edge right slide pop out stack

Source: Internet
Author: User

iOS View controller left edge right slide pop out stack

After IOS7.0, Apple optimized a small function, that is, for the Uinavagationcontroller stack of Uiviewcontroller, as long as the left edge of the view controller to the right slide, the view controller will pop out of the stack (if for the non-root view controller, of course). The implementation of the method is very simple, one sentence to fix:

self.navigationController.interactivePopGestureRecognizer.enabled = YES;

In fact, for a view controller, the default value for this property is yes, so it is not set and can also implement the function of right-slide pop. However, this feature is very limited because it does not allow the current view controller to customize the Leftbarbuttonitem, and once customized, the right slide function becomes invalid. Here's one way:

Self.navigationController.interactivePopGestureRecognizer.delegate = nil;

After you set the proxy to nil, you can right-swipe pop even after customizing the Leftbarbuttonitem.

In fact, if you customize the Leftbarbuttonitem, the usual practice is to reset the proxy:

-(void) Viewdidappear: (BOOL) Animated{__weak typeof (self) weakself = self; Self.navigationController.interactivePopGestureRecognizer.delegate = weakself;}

The gesture protocol can then be implemented:

#pragma mark-uigesturerecognizerdelegate-(BOOL) Gesturerecognizershouldbegin: (uigesturerecognizer*) gesturerecognizer{    //Determine if Rootviewcontroller    if (Self.navigationcontroller && Self.navigationController.viewControllers.count = = 1) {        return NO;    }    return YES;}

iOS development-View controller left edge right slide pop out stack

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.