【发布时间】:2014-09-18 09:46:32
【问题描述】:
为了显示警报,我使用SDCAlertView(UIAlertView 的克隆)。我想通过点击 UIActionSheet 等屏幕来解除警报。
【问题讨论】:
标签: ios sdcalertview sdcalertcontroller
为了显示警报,我使用SDCAlertView(UIAlertView 的克隆)。我想通过点击 UIActionSheet 等屏幕来解除警报。
【问题讨论】:
标签: ios sdcalertview sdcalertcontroller
与UIAlertView 不同,SDCAlertView 作为视图添加到视图层次结构中。这意味着您可以简单地将轻击手势识别器添加到SDCAlertView 的超级视图,该视图调用[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()
}
}
}
【讨论】: