No Swipe Back when hiding Navigation Bar in UINavigationController

前端 未结 18 688
生来不讨喜
生来不讨喜 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 07:07

    Xamarin Answer:

    Implement the IUIGestureRecognizerDelegate Interface in your ViewController's Class definition:

    public partial class myViewController : UIViewController, IUIGestureRecognizerDelegate
    

    In your ViewController add the following method:

    [Export("gestureRecognizerShouldBegin:")]
    public bool ShouldBegin(UIGestureRecognizer recognizer) {
      if (recognizer is UIScreenEdgePanGestureRecognizer && 
          NavigationController.ViewControllers.Length == 1) {
        return false;
      }
      return true;
    }
    

    In your ViewController's ViewDidLoad() add the following line :

    NavigationController.InteractivePopGestureRecognizer.Delegate = this;
    

提交回复
热议问题