Wenn Sie swift verwenden und preferredStyle ist Alarm Sie Schnipsel wie unten verwenden:
func showAlertBtnClicked(sender: UIButton) {
let alert = UIAlertController(title: "This is title", message: "This is message", preferredStyle: .Alert)
self.presentViewController(alert, animated: true, completion:{
alert.view.superview?.userInteractionEnabled = true
alert.view.superview?.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.alertControllerBackgroundTapped)))
})
}
func alertControllerBackgroundTapped()
{
self.dismissViewControllerAnimated(true, completion: nil)
}
Mit schnellen 3:
func showAlertBtnClicked(sender: UIButton) {
let alert = UIAlertController(title: "This is title", message: "This is message", preferredStyle: .alert)
self.present(alert, animated: true) {
alert.view.superview?.isUserInteractionEnabled = true
alert.view.superview?.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.alertControllerBackgroundTapped)))
}
}
func alertControllerBackgroundTapped()
{
self.dismiss(animated: true, completion: nil)
}
Hallo Leizh00701 check this out http://stackoverflow.com/questions/25466718/uialertcontroller-handle-dismiss-upon-click-outside-ipad – Harish
, was die Absender ist: UIControl * aControl = (UIControl *) Absender; – leizh00701
UIControl ist die Basisklasse für Steuerobjekte wie Schaltflächen und Schieberegler, die die Benutzerabsicht an die Anwendung übermitteln. Bitte überprüfen Sie dies unter https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIControl_Class/index .html – Harish