iOS development-swipe right to return to the gesture

Source: Internet
Author: User

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

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.