iOS-导航控制器全屏侧滑

导航控制器返回,网上已经有开源的FDFullscreenPopGesture,屏幕本身边缘也可以是可以侧滑返回的,如果自己想简单的时候也可以,首要要获取控制器的interactivePopGestureRecognizer,然后获取手势的delegate~
如下所示:

**2016-12-08 16:48:32.573FlyElephant[21021:320874] ****全屏手势****:; target= <(action=handleNavigationTransition:, target=<_UINavigationInteractiveTransition 0x7fc04d8097c0>)>>**
**2016-12-08 16:48:32.573 FlyElephant[21021:320874] ****全屏手势****Target:<_UINavigationInteractiveTransition: 0x7fc04d8097c0>**
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"FlyElephant";
    [self.navigationController.navigationBar setBarTintColor:[UIColor greenColor]];
    
    NSLog(@"全屏手势:%@",self.navigationController.interactivePopGestureRecognizer);
    NSLog(@"全屏手势Target:%@",self.navigationController.interactivePopGestureRecognizer.delegate);
    
    id target = self.navigationController.interactivePopGestureRecognizer.delegate;
    // 创建全屏滑动手势,调用系统自带滑动手势的target的action方法
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:target action:@selector(handleNavigationTransition:)];
    pan.delegate = self;
    // 给导航控制器的view添加全屏滑动手势
    [self.view addGestureRecognizer:pan];
    // 禁止使用系统自带的滑动手势
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
    // 根控制器不侧滑返回
    if (self.childViewControllers.count == 1) {
        // 表示用户在根控制器界面,就不需要触发滑动手势,
        return NO;
    }
    return YES;
}

你可能感兴趣的:(iOS-导航控制器全屏侧滑)