1. 程式人生 > >ios自定義返回按鈕後沒有滑動返回手勢處理方法

ios自定義返回按鈕後沒有滑動返回手勢處理方法

A push B push C在C中不需要加以下程式碼

在A檢視中增加下面程式碼

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}

在Apush到B前加上
 //防止自定義左返回按鈕後左滑返回手勢消失
            if ([wself.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)])
            {
                wself.navigationController.interactivePopGestureRecognizer.enabled = YES;
                wself.navigationController.interactivePopGestureRecognizer.delegate = nil;
            }
            [wself.navigationController pushViewController:billingSelectedController animated:YES];

在b檢視中自定義導航返回按鈕
-(void)createBackBarBtn{
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 0, 40, 40);
    [btn setImageEdgeInsets:UIEdgeInsetsMake(0,-30, 0, 0)];
    [btn setImage:[UIImage imageNamed:@"backBt"] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
}
注意:在該句
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
程式碼只能在A中寫,如果在他的子檢視中加入可能會引起滑動手勢取消