In iOS, the navigation controller has its own slide-by default, and when the user slides to the left (left edge) of the interface, the slide-through function is available. However, we often need to slide around the screen at any point in the development process and need to go back to the previous interface.
More to say unintentionally, directly read the code:
Part:
Part of the Code (second interface):
#import "CJSecondViewController.h"
@interface Cjsecondviewcontroller () <UIGestureRecognizerDelegate>
@end
@implementation Cjsecondviewcontroller
-(void) Viewdidload {
[Super Viewdidload];
NSLog (@ "%@", Self.navigationController.interactivePopGestureRecognizer);
Gets the target object with the system's own swipe gesture
ID target = self.navigationController.interactivePopGestureRecognizer.delegate;
Create a full-screen swipe gesture that calls the system's action method with the target of the swipe gesture
Uipangesturerecognizer *pan = [[Uipangesturerecognizer alloc] initwithtarget:target action: @selector ( Handlenavigationtransition:)];
Set gesture proxy, intercept gesture trigger
Pan.delegate = self;
Add a full-screen swipe gesture to the navigation controller's view
[Self.view Addgesturerecognizer:pan];
Disable use of the system's own sliding gestures
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
Do any additional setup after loading the view.
Self.view.backgroundColor = [Uicolor Whitecolor];
Self.title = @ "Picture Show";
Uiimageview *imageview = [[Uiimageview alloc] Initwithframe:cgrectmake (50, 200, 200, 200)];
Imageview.image = [UIImage imagenamed:@ "4.jpg"];
[Self.view Addsubview:imageview];
}
When to call: The agent is asked before each trigger gesture, whether it is triggered or not.
Action: Intercept gesture Trigger
-(BOOL) Gesturerecognizershouldbegin: (Uigesturerecognizer *) gesturerecognizer{
Note: Only the non-root controller has the sliding return function, the root controller does not.
Determine if the navigation controller has only one sub-controller, if there is only one child controller, it must be the root controller
if (Self.childViewControllers.count = = 1) {
Indicates that the user does not need to trigger a swipe gesture on the root controller interface.
return NO;
}
return YES;
}
@end
For specific reasons and details, please continue to view: http://www.cocoachina.com/ios/20150811/12897.html
Navigation controller in IOS full screen right swipe back to previous interface