Ios 如何使用点击手势关闭SDCAlertView?

Ios 如何使用点击手势关闭SDCAlertView?,ios,sdcalertview,sdcalertcontroller,Ios,Sdcalertview,Sdcalertcontroller,要显示警报,我使用(UIAlertView的克隆)。我想通过点击屏幕(如UIActionSheet)来解除警报。与UIAlertView不同,SDcalerView作为视图添加到视图层次结构中。这意味着您可以简单地将点击手势识别器添加到SDCAlertView的superview,该superview调用[SDCAlertView dismissWithClickedButtonIndex:animated://我找到了一种方法。与iOS 7+兼容,但可在8+上使用 class SmartAle

要显示警报,我使用(UIAlertView的克隆)。我想通过点击屏幕(如UIActionSheet)来解除警报。

UIAlertView
不同,
SDcalerView
作为视图添加到视图层次结构中。这意味着您可以简单地将点击手势识别器添加到
SDCAlertView
的superview,该superview调用
[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()
        }
    }
}
class智能警报
{
静态var backroundWindow:UIWindow!
静态var警报控制器:SDCAlertController!
类func showAlertWithTitle(标题:String!、消息:String!、操作标题:String)
{
如果(iOS8)
{
self.backroundWindow=UIWindow(框架:UIScreen.mainScreen().bounds)
self.backroundWindow.backgroundColor=UIColor.clearColor()
self.backroundWindow.rootViewController=EmptyViewController()
self.backroundWindow.windowLevel=UIWindowLevelAlert
self.backroundWindow.makeKeyAndVisible()文件
}
self.alertController=SDCAlertController(标题:标题,消息:消息,首选样式:。警报)
self.alertController.addAction(SDCalerAction)(标题:actionTitle,样式:。默认值,处理程序:
{
())->
self.backroundWindow=nil
}))
self.alertController.presentWithCompletion(无)
}
类func dismissAlert()
{
self.alertController.dismissWithCompletion
{
self.backroundWindow=nil
}
}
}
类EmptyViewController:UIViewController
{
覆盖func touchesBegined(触摸:设置,withEvent事件:UIEvent)
{
SmartAlert.dismissAlert()
}
覆盖func MotionStart(运动:UIEventSubtype,withEvent事件:UIEvent)
{
如果运动==UIEventSubtype.MotionShake
{
SmartAlert.dismissAlert()
}
}
}

现在如何使用SDCAlertController?您可以尝试将其添加到视图控制器的视图中,但这可能不是您想要的