[英]How to dismiss SDCAlertView with tap gesture?
与UIAlertView
不同, SDCAlertView
作为视图添加到视图层次结构。 这意味着您可以简单地将轻SDCAlertView
手势识别器添加到SDCAlertView
视图,该[SDCAlertView dismissWithClickedButtonIndex:animated:]
视图调用[SDCAlertView dismissWithClickedButtonIndex:animated:]
。
我找到了一种方法。 与iOS 7+兼容,但在8+上点击即可关闭。
class SmartAlert
{
static var backroundWindow: UIWindow!
static var alertController: SDCAlertController!
class func showAlertWithTitle(title: String!, message: String!, actionTitle: String)
{
if (iOS8)
{
self.backroundWindow = UIWindow(frame: UIScreen.mainScreen().bounds)
self.backroundWindow.backgroundColor = UIColor.clearColor()
self.backroundWindow.rootViewController = EmptyViewController()
self.backroundWindow.windowLevel = UIWindowLevelAlert
self.backroundWindow.makeKeyAndVisible()
}
self.alertController = SDCAlertController(title: title, message: message, preferredStyle: .Alert)
self.alertController.addAction(SDCAlertAction(title: actionTitle, style: .Default, handler:
{
(_) -> Void in
self.backroundWindow = nil
}))
self.alertController.presentWithCompletion(nil)
}
class func dismissAlert()
{
self.alertController.dismissWithCompletion
{
self.backroundWindow = nil
}
}
}
class EmptyViewController: UIViewController
{
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent)
{
SmartAlert.dismissAlert()
}
override func motionBegan(motion: UIEventSubtype, withEvent event: UIEvent)
{
if motion == UIEventSubtype.MotionShake
{
SmartAlert.dismissAlert()
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.