ios - 如何使用 MDCAertController Material Design 禁用触摸外屏关闭 View - swift

标签 ios swift uialertview material-components-ios

我是 iOS 编程新手,现在着迷于使用 google 提供的 MaterialComponents。现在我在名为 Dialog 的组件中面临一个问题。

当 View 在屏幕上弹出时,当我触摸该弹出 View 之外时,该 View 已被关闭。我不希望这种情况发生在我的应用程序中。

我不希望用户单击弹出 View 外部来关闭该弹出 View 。我想要的只是希望用户单击我提供给用户选择的操作按钮,然后仅在单击该操作按钮时应关闭 View 。

非常高兴您能提供帮助。

最佳答案

MDCAlertController 继承自 UIViewController

因此,为了限制用户在 MDCAlertController 外部单击,您必须访问其名为 view 的属性,然后访问 superview?.subviews[0].isUserInteractionEnabled =假

我已经使用 MDCAertController 完成了一个示例

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
    })

关于ios - 如何使用 MDCAertController Material Design 禁用触摸外屏关闭 View - swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53225321/

相关文章:

ios - 如何将 UITextView 的文本设置为粗体且不可点击

ios - 我需要做些什么才能在我的非弧形项目中通过 Cocoapods 使用 RestKit 2.0 吗?

swift - 使用 Alamofire 和 SwiftyJson 从函数返回值

generics - 在 Swift 数组中存储通用对象

ios - 如何在文本字段和键盘中隐藏蓝色光标?

ios - 点击按钮时 UIAlertView 崩溃

objective-c - [Obj-C]我如何在使用 NSTask 后做一个 IBAlert?

ios - 从另一个 View Controller 将对象添加到数组

ios - UIAlertView + TextField = 错误?

objective-c - 如何从其他类访问方法而不在 Objective-C 中创建对象?