I\'m new to IOS programming, I\'m displaying a view when a button is clicked, using the following code inside the button method.
@IBAction func moreButton(_
Swift 5.1:
This should help to dismiss the view once touched outside of the view.
override func touchesBegan(_ touches: Set, with event: UIEvent?) { let touch = touches.first if touch?.view != self.yourView { self.dismiss(animated: true, completion: nil) } }