2

I have UIViewController add to my view by present. Now user can remove this view by drag to bottom of screen. How can I disable it?

I try by

view.isUserInteractionEnabled = false

and

override func viewDidLoad() {
        self.transitioningDelegate = self
    }

extension MyViewController: UIViewControllerTransitioningDelegate {
    func interactionControllerForDismissal(using animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
        return nil
    }

    func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        return nil
    }
}

But user still can dismiss it.

JamesVoo
  • 145
  • 1
  • 11
  • As I understand your view controller implement some custom logic to be dismissed by drag to bottom. Probably it's some pan gesture recognizer in controller implementation or in parent controller implementation. You just need remove/disable it. – Anton Rodzik Aug 30 '19 at 11:43
  • @AntonRodzik - no, I don't have any custom logic. This is default. In this view controller I only set cornerRadius and text in label – JamesVoo Aug 30 '19 at 11:54

3 Answers3

2

You need disable your pan gesture to disable drag dismiss.

Thanh Vu
  • 1,599
  • 10
  • 14
  • I try `if let gesutreRecognize = self.navigationController?.navigationBar.gestureRecognizers { for gesture in gesutreRecognize where gesture is UIPanGestureRecognizer { gesture.isEnabled = false } }` In ViewWillAppear and ViewDidLoad and still didn't work – JamesVoo Sep 02 '19 at 07:41
  • Can you put your full sample proj? – Thanh Vu Sep 02 '19 at 08:47
  • Unfortunately I can't. NDA :) – JamesVoo Sep 02 '19 at 08:48
  • Because gesture you need disable maybe from another screen that control your dismiss. Please find it from parent controller or another container controller. – Thanh Vu Sep 02 '19 at 08:49
  • Yeah, now I'm doing it, and I think it might work :) – JamesVoo Sep 02 '19 at 08:50
  • Ok, I found the solution. Just like @Than Vu wrote, I using another screen to control my view. I used PopupDialog framework(https://github.com/Orderella/PopupDialog), and when I init it, I add `panGestureDismissal: false` And now works fine :) – JamesVoo Sep 02 '19 at 08:54
  • @JamesVoo congratulation – Thanh Vu Sep 02 '19 at 08:55
1

You can use this line in the viewController's viewDidLoad method:

self.navigationController.interactivePopGestureRecognizer.enabled = NO;

You can refer this.

Komal Goyani
  • 779
  • 6
  • 25
  • 1
    It's renamed to `self.navigationController?.interactivePopGestureRecognizer?.isEnabled = false` but still don't work – JamesVoo Aug 30 '19 at 11:56
1

See Bilal's answer here

.isModalInPresentation = true worked for me

adougies
  • 131
  • 1
  • 10