iOS development swipe to the right to return the gesture. How to set up in Navigationcontroller

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.