iOS左滑手势返回的实现

#import <UIKit/UIKit.h>

@interface CustomNavigationController : UINavigationController<UINavigationControllerDelegate>

@end


 
 
#import "CustomNavigationController.h"

@interface CustomNavigationController ()<UIGestureRecognizerDelegate>

@property(nonatomic,weak) UIViewController* currentShowViewController;
@end


@implementation CustomNavigationController


-(id)initWithRootViewController:(UIViewController *)rootViewController{
    CustomNavigationController* nvc = [super initWithRootViewController:rootViewController];
    self.interactivePopGestureRecognizer.delegate = self;
    nvc.delegate = self;
    return nvc;
}

-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
}
-(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if (navigationController.viewControllers.count == 1)
        self.currentShowViewController=Nil;
    else
        self.currentShowViewController = viewController;
}

-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
    if (gestureRecognizer == self.interactivePopGestureRecognizer) {
        return (self.currentShowViewController == self.topViewController); //the most important
    }
    return YES;
}

你可能感兴趣的:(ios,UIGesture)