iOS导航栏--侧滑失效问题

搜了好多的资料,千篇一律都是说要重写nav

经过好友指点,如下代码也是可以的。不需要重写nav
/**
 * 思路,通过获取nav的target 来调用nav的handleNavigationTransition: 这个转场动画
 */
- (void)viewDidLoad
{
    [super viewDidLoad];
/**
     * 右滑返回
     * 调用系统的方法
     */
    self.navigationController.interactivePopGestureRecognizer.enabled=NO;
    id target = self.navigationController.interactivePopGestureRecognizer.delegate;
    UIPanGestureRecognizer *pan=[[UIPanGestureRecognizer alloc]initWithTarget:target action:@selector(handleNavigationTransition:)];
    pan.delegate = self;
    [self.view addGestureRecognizer:pan];
}
解决一个bug(根试图右滑,导致无法push的问题)
#pragma mark delegate
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
    if (self.navigationController.viewControllers.count <= 1 ) {
        return NO;
    }
    return YES;
}

你可能感兴趣的:(iOS导航栏--侧滑失效问题)