No Swipe Back when hiding Navigation Bar in UINavigationController

前端 未结 18 683
生来不讨喜
生来不讨喜 2020-12-04 06:34

I love the swipe pack thats inherited from embedding your views in a UINavigationController. Unfortunately i cannot seem to find a way to hide the Naviga

18条回答
  •  北海茫月
    2020-12-04 06:58

    I've tried this and it's working perfectly : How to hide Navigation Bar without losing slide-back ability

    The idea is to implement "UIGestureRecognizerDelegate" in your .h and add this to your .m file.

    - (void)viewWillAppear:(BOOL)animated {
    // hide nav bar
    [[self navigationController] setNavigationBarHidden:YES animated:YES];
    
    // enable slide-back
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
        self.navigationController.interactivePopGestureRecognizer.delegate = self;
      }
    }
    
    - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
       return YES;  
    }
    

提交回复
热议问题