Sliding right to back function in Navigationcontroller
System-provided backbarbuttonitem, without adding any code to achieve the right to slide back function, but often to modify the button style, etc., you need to customize the Leftbarbuttonitem, when the right swipe is invalidated. The problem can be resolved in the following ways. (I have experimented with it myself)
Mainly by setting the Navigationcontroller. Interactivepopgesturerecognizer Some properties of this gesture, this gesture can be viewed through the SDK, which does not detail
1. Self . Navigationcontroller. Interactivepopgesturerecognizer. Enabled = YES | NO; Whether the gesture is valid or not
2. self. Navigationcontroller. Interactivepopgesturerecognizer. Delegate = self; Gesture proxy, typically set to Self
1, 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 will have 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,b
Navigationcontroller's Rootview is set to a, click the button in a and push B. In a-(void) Viewdidappear: (BOOL) animated method, add 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 no sliding
}
}
Then add the-(void) Viewdidload method in B
-(void) Viewdidload
{
Configure the Back 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;
if ([[[[ uidevice currentdevice] systemversion] floatvalue] >= 7.0) {
Self . Navigationcontroller. Interactivepopgesturerecognizer. Delegate = Self ;
}
}
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 the returned operation (without adding a piece of code to each Viewcontroller) while creating the Leftbarbutton. Then add only a (void) to the rootview of Navigationcontroller Viewdidappear: (BOOL) animated method.
Well, if there's a better acceptance, everybody shoot bricks.
iOS development swipe to the right to return the gesture. How to set up in Navigationcontroller