0

I have a custom pop up which I have made using a UIViewController (presentation: 'over current context') - please see below. What I would like to do is dismiss the UIViewController once the user touches the top - dark half- of the screen, which does not contain the menu options. What event can i trigger to get this to work?

enter image description here

dean
  • 321
  • 3
  • 17

1 Answers1

1

You can add a tap gesture to the darkView and inside it do

let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap(_:)))
mydarkView.addGestureRecognizer(tapGesture)

//

// 3. this method is called when a tap is recognized
@objc func handleTap(_ sender: UITapGestureRecognizer) {
     self.dismiss(animated:true,completion:true)
}

OR use

override func touchesBegan(_ touches: Set<UITouch>, 
         with event: UIEvent?)
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87