-1

I want to hide my alert when any one click on view. Logout alert should be hide when click on black shadow area

please anyone help me.

sunil kumar
  • 53
  • 2
  • 9
  • Possible duplicate of [How to dismiss UIAlertController when tap outside the UIAlertController?](https://stackoverflow.com/questions/30075832/how-to-dismiss-uialertcontroller-when-tap-outside-the-uialertcontroller) – Rakesha Shastri Aug 31 '18 at 10:18
  • Possible duplicate of [UIAlertController handle dismiss upon click outside (IPad)](https://stackoverflow.com/questions/25466718/uialertcontroller-handle-dismiss-upon-click-outside-ipad) – Enea Dume Aug 31 '18 at 10:19

1 Answers1

0

First of all you have to enable the interaction for the superview of the alert.

myAlert.view.superview.isUserInteractionEnabled = true

then you have to add a click gesture to superview which inturn will dismiss your view.

myAlert.view.superview.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.removeAlert)))
SUMIT NIHALANI
  • 387
  • 1
  • 10