IOS development right slide back to upper level controller

Source: Internet
Author: User

#import <objc/runtime.h>

@interface Uinavigationcontroller (Transition) <UIGestureRecognizerDelegate>

-(void) transitionpangesturedidload;

@end

@interface Dlnavigationtransition ()

@end

@implementation Dlnavigationtransition

/**

* Start Right slide pop

*/

+ (void) enablenavigationtransitionwithpangestureback

{

Static dispatch_once_t Oncetoken;

Dispatch_once (&oncetoken, ^{

Method Viewdidloadmethod = Class_getinstancemethod ([Uinavigationcontroller class], @selector (viewdidload));

Method Transitionpangesturedidloadmethod = Class_getinstancemethod ([Uinavigationcontroller class], @selector ( Transitionpangesturedidload));

Method_exchangeimplementations (Viewdidloadmethod, Transitionpangesturedidloadmethod);

});

}

@end

@implementation Uinavigationcontroller (Transition)

-(void) transitionpangesturedidload

{

if ([Self Iskindofclass:[uinavigationcontroller class]])

{

[Self transitionpangesturedidload];

1. Get the target object for the system Interactivepopgesturerecognizer object

ID target = self.interactivePopGestureRecognizer.delegate;

2. Create a swipe gesture, Taregt set the target of the Interactivepopgesturerecognizer, so the target action method is automatically called when the interface is sliding.

Handlenavigationtransition is a private class _uinavigationinteractivetransition method, the system is mainly implemented in this method animation.

Uipangesturerecognizer *pan = [[Uipangesturerecognizer alloc] init];

[Pan Addtarget:target action:nsselectorfromstring (@ "handlenavigationtransition:")];

3. Setting up the agent

Pan.delegate = self;

4. Add to the view on the navigation controller

[Self.view Addgesturerecognizer:pan];

5. Disable slide gestures for the system

self.interactivePopGestureRecognizer.enabled = NO;

}

}

#pragma mark-the swipe starts to trigger

-(BOOL) Gesturerecognizershouldbegin: (Uigesturerecognizer *) Gesturerecognizer

{

Uipangesturerecognizer *pan = (Uipangesturerecognizer *) Gesturerecognizer;

Cgpoint Translat = [Pan TranslationInView:pan.view];

if (Translat.x < 0) {

return NO;

}

Only the navigation of the root controller does not require a right-sliding return feature.

if (Self.viewControllers.count <= 1)

{

return NO;

}

return YES;

}

@end

Just wait for you to copy the code.

IOS development right slide back to upper level controller

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.