天天看點

如何禁止手機側滑傳回上一個頁面

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    // 開啟傳回手勢
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    }
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    // 開啟傳回手勢
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    }
}      
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    [self.playerView startPlaying];
    [self popGestureChange:self enable:NO];
//    // 開啟傳回手勢
//    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
//        self.navigationController.interactivePopGestureRecognizer.delegate = self;
//    }
}
-(void)popGestureChange:(UIViewController *)vc enable:(BOOL)enable{

    if ([vc.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {

        //周遊所有的手勢

        for (UIGestureRecognizer *popGesture in vc.navigationController.interactivePopGestureRecognizer.view.gestureRecognizers) {

            popGesture.enabled = enable;

        }

    }

}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.playerView pausePlaying];
    [self popGestureChange:self enable:YES];
//    // 開啟傳回手勢
//    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
//        self.navigationController.interactivePopGestureRecognizer.delegate = nil;
//    }
    self.navigationController.navigationBar.hidden = NO;
}      
iOS