Navigationcontroller to the right to move back to the function system provides the Backbarbuttonitem, do not add any code to achieve the right to slide back function, but often to modify the style of the button, etc., You need to customize the Leftbarbuttonitem, and then swipe to the right to fail. The problem is resolved by the following method.mainly by setting the Navigationcontroller. InteractivepopgesturerecognizerUIGestureRecognizerDelegate1.self. Navigationcontroller. Interactivepopgesturerecognizer. Enabled = YES | NO; Whether the gesture is valid or not2. self. Navigationcontroller. Interactivepopgesturerecognizer. Delegate = self; Gesture proxy, typically set to Self1, the default setting in Viewcontroller is yes, that is, the gesture is valid. Following the properties set in 2, the current Viewcontroller can implement the right sliding back function, But when you go back to Navigationcontroller's rootview and make the right swipe again, the program has a problem (when you push the child controller again, the card cannot jump at the current interface). The effective solution is as follows: Description: There are two Controllera,bnavigationcontroller Rootview set to A, click on the button in a and push B. In A-(void) Viewdidappear: (BOOL) The animated method is added to self . Navigationcontroller. Interactivepopgesturerecognizer. Enabled = NO; code is as follows:
-(void) Viewdidappear: (BOOL) animated{ if ([[[[[Uidevice Currentdevice] systemversion] floatvalue] >= 7.0) { self.navigationController.interactivePopGestureRecognizer.enabled = NO; Let Rootview disable sliding }}
And then in B-(void) Viewdidload method is added to the
-(void) viewdidload{ //Configuration return button Uibarbuttonitem * Backitem = [self barbuttonforimagenames:@[@ "icon-back", @ "", @ "" ] Action: @selector (Popback)]; Backitem.title = @ ""; if ([[[[Uidevice Currentdevice] systemversion] floatvalue] >= 7.0) { self.navigationController.interactivePopGestureRecognizer.enabled = YES; Self.navigationController.interactivePopGestureRecognizer.delegate = self; } Self.navigationItem.leftBarButtonItem = Backitem;}
This ensures that the A will not be stuck in the A interface when it is PUSHB to the right again.Re-project in general will create a unified style interface, generally will create a basic viewcontroller, and then this viewcontroller extension of a configuration Leftbarbutton method, in the method to add the viewdidload of B code, This allows you to add a return operation (without adding a piece of code to each Viewcontroller) while creating the Leftbarbutton. Then add only a to the Rootview of Navigationcontroller (void) Viewdidappear: (BOOL) animated method.
iOS development-swipe right to return to the gesture