I use ViewController for a pop. Added tap to close the window to the main View

 let viewTap = UITapGestureRecognizer(target: self, action: #selector(dismissSelf)) view.addGestureRecognizer(viewTap) @objc func dismissSelf() { self.dismiss(animated: false, completion: nil) } 

How to disable the triggering tapa when clicking on the View lying on top?

    2 answers 2

    Assign your controller delegate to UITapGestureRecognizer

     viewTap.delegate = self 

    and check where the click occurs:

     extension ViewController: UIGestureRecognizerDelegate { func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool { return touch.view == view } } 
    • Seem you didn’t understand my question at all or I didn’t formulate it correctly - Daniyal1909
    • @ Daniyal1909 then write in more detail, attach an example of the project where you need to solve the problem .. - VAndrJ

    Try setting view, which should be inactive, property .isUserInteractionEnabled to false

    • When adding such a parameter, all tapes on top of the view will be disabled (the clickable part of the popup will be turned off), but not those that are lower - Daniyal1909
    • To be honest, when I did a popup view, I used a separate blur view. I have already laid a twist with popup on the view of the blur effect. It's easier and it looks nice (the lower view is obscured and becomes inactive, and the pop-up show is emphasized). In extreme cases, add a twist with a transparent color under the popup and don’t bother with the reverse activation of the buttons and motion recognizers on the root twist - Morgan Freewalker
    • But how about making a separate ViewController and setting it up as a popover?) - Morgan Freewalker