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
  • 301
  • 3
  • 14

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?)
Sh_Khan
  • 93,445
  • 7
  • 57
  • 76