1. 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:@ "Wang Yu" 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.
@interface ViewController () @[email protected] ViewController- (void) viewdidload { [super viewdidload]; // Custom return button uibutton * 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 returns proxy for gesture _delegate = self.navigationController.interactivePopGestureRecognizer.delegate; // set the system return gesture proxy for the current controller self.navigationController.interactivePopGestureRecognizer.delegate = self; }}- (void) Viewwilldisappear: (BOOL) Animated { [super viewWillDisappear:animated]; // set the system return gesture agent for the system we just entered the controller to record the return gesture agent &NBSp; 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.navigationcontroller.viewcontrollers.count > 1;} @end
IOS Custom Back button, leave the system sliding back