original link
The custom Back button retains the system swipe back gesture. Gif1. Introduction
Using the iphone, the favorite is to use its sliding back. As a developer, when we write a lot of pages, there is always a reason why the system's sliding back is not available. Use the navigation bar to push out a controller, We have customized a return button in the controller. This way the system defaults to the swipe back gesture effect is gone.
2. Workaround
[1] From a This controller push to b this controller, we want to customize the B's Return button, we can set in a
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"王俨" style:UIBarButtonItemStylePlain target:nil action:nil];
[2] in the B Controller set back button, I think this should be the choice most people like, but when we set in the B controller, we self.navigationItem.leftBarButtonItem found that the system's sliding return gesture failed. So how can you keep the system sliding back gesture, we can do this in the B controller.
@interfaceViewcontroller () <Uigesturerecognizerdelegate>@end@implementationViewcontroller {id<Uigesturerecognizerdelegate> _delegate}-(void) Viewdidload {[Super Viewdidload];Custom Back buttonUIButton *button = [[UIButton Alloc]initwithframe:CGRectMake (0,0,44,44)]; [Button Settitle:@ "Wang Yu 2" forstate:UIControlStateNormal]; [Button settitlecolor:[Uicolor Blackcolor] Forstate:UIControlStateNormal]; [Button AddTarget:Self action:@selector (back:) forControlEvents:UIControlEventTouchUpInside];Self. Navigationitem. Leftbarbuttonitem = [[Uibarbuttonitem Alloc]initwithcustomview:button];} - (void) Back: (UIButton *) button {[Self. Navigationcontroller popviewcontrolleranimated:YES];} - (void) Viewwillappear: (BOOL) Animated {[Super viewwillappear:animated];if (Self. Navigationcontroller. viewcontrollers. Count >1) {Record system return gesture proxy _delegate =Self. Navigationcontroller. Interactivepopgesturerecognizer. Delegate;Set the system return gesture for the agent for the current controllerSelf. Navigationcontroller. Interactivepopgesturerecognizer. Delegate =Self }}- (void) Viewwilldisappear: (BOOL) Animated {[Super viewwilldisappear:animated];The agent that sets the system return gesture is the return gesture agent for the system that we recorded when we first entered the controller.Self. Navigationcontroller. Interactivepopgesturerecognizer. Delegate = _delegate;}#pragma mark-uigesturerecognizerdelegate-(bool) Gesturerecognizershouldbegin: (UIGestureRecognizer *) Gesturerecognizer {return self .navigationcontroller.childviewcontrollers.count > 1;} -(bool) Gesturerecognizer: (uigesturerecognizer *) Gesturerecognizer Shouldrecognizesimultaneouslywithgesturerecognizer: ( Uigesturerecognizer *) Othergesturerecognizer {return self< Span class= "hljs-variable" >.navigationcontroller.viewcontrollers .count > 1;} @end
IOS Custom Back button, leave the system sliding back