Navigation controller in IOS full screen right swipe back to previous interface

Source: Internet
Author: User

In iOS, the navigation controller has its own slide-by default, and when the user slides to the left (left edge) of the interface, the slide-through function is available. However, we often need to slide around the screen at any point in the development process and need to go back to the previous interface.

More to say unintentionally, directly read the code:

Part:

Part of the Code (second interface):

#import "CJSecondViewController.h"

@interface Cjsecondviewcontroller () <UIGestureRecognizerDelegate>

@end

@implementation Cjsecondviewcontroller

-(void) Viewdidload {

[Super Viewdidload];

NSLog (@ "%@", Self.navigationController.interactivePopGestureRecognizer);

Gets the target object with the system's own swipe gesture

ID target = self.navigationController.interactivePopGestureRecognizer.delegate;

Create a full-screen swipe gesture that calls the system's action method with the target of the swipe gesture

Uipangesturerecognizer *pan = [[Uipangesturerecognizer alloc] initwithtarget:target action: @selector ( Handlenavigationtransition:)];

Set gesture proxy, intercept gesture trigger

Pan.delegate = self;

Add a full-screen swipe gesture to the navigation controller's view

[Self.view Addgesturerecognizer:pan];

Disable use of the system's own sliding gestures

self.navigationController.interactivePopGestureRecognizer.enabled = NO;

Do any additional setup after loading the view.

Self.view.backgroundColor = [Uicolor Whitecolor];

Self.title = @ "Picture Show";

Uiimageview *imageview = [[Uiimageview alloc] Initwithframe:cgrectmake (50, 200, 200, 200)];

Imageview.image = [UIImage imagenamed:@ "4.jpg"];

[Self.view Addsubview:imageview];

}

When to call: The agent is asked before each trigger gesture, whether it is triggered or not.

Action: Intercept gesture Trigger

-(BOOL) Gesturerecognizershouldbegin: (Uigesturerecognizer *) gesturerecognizer{

Note: Only the non-root controller has the sliding return function, the root controller does not.

Determine if the navigation controller has only one sub-controller, if there is only one child controller, it must be the root controller

if (Self.childViewControllers.count = = 1) {

Indicates that the user does not need to trigger a swipe gesture on the root controller interface.

return NO;

}

return YES;

}

@end

For specific reasons and details, please continue to view: http://www.cocoachina.com/ios/20150811/12897.html

Navigation controller in IOS full screen right swipe back to previous interface

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.