我是新的 iOS 编程,现在对使用MaterialComponents
google 提供的程序很着迷。现在我在名为Dialog
.
当我在该弹出视图之外触摸该视图时,该视图已在屏幕上弹出,然后该视图已被关闭。我不希望在我的应用程序中发生这种情况。
我不希望用户单击外部弹出视图来关闭该弹出视图。我想要什么,我只希望用户单击我为用户选择提供的操作按钮,然后仅在单击该操作按钮时视图应该被关闭。
真的很高兴你能帮忙。
我是新的 iOS 编程,现在对使用MaterialComponents
google 提供的程序很着迷。现在我在名为Dialog
.
当我在该弹出视图之外触摸该视图时,该视图已在屏幕上弹出,然后该视图已被关闭。我不希望在我的应用程序中发生这种情况。
我不希望用户单击外部弹出视图来关闭该弹出视图。我想要什么,我只希望用户单击我为用户选择提供的操作按钮,然后仅在单击该操作按钮时视图应该被关闭。
真的很高兴你能帮忙。
MDCAlertController
继承自UIViewController
。
因此,为了限制用户点击外部MDCAlertController
,您必须访问其名为的属性view
,然后superview?.subviews[0].isUserInteractionEnabled = false
我已经使用 MDCAlertController 完成了一个示例
let alert = MDCAlertController(title: title, message: message)
alert.buttonTitleColor = UIColor(red:0.03, green:0.62, blue:0.09, alpha:1.0)
//MDCAlertControllerThemer.applyScheme(alertScheme, to: alert)
let okayAction = MDCAlertAction(title: "Okay") { (action) in
print("User click okay")
}
let cancelAction = MDCAlertAction(title: "Cancel", handler: nil)
alert.addAction(okayAction)
alert.addAction(cancelAction)
self.present(alert, animated: true, completion: {
// When the Dialog view has pop up on screen then just put this line of code when Dialog view has completed pop up.
alert.view.superview?.subviews[0].isUserInteractionEnabled = false
})
用这个。
let alert = MDCAlertController(title: title, message: message)
alert.mdc_dialogPresentationController.dismissOnBackgroundTap = false