#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