我正在尝试禁用我拥有的UIContextualAction

let picture = UIContextualAction(style: .normal, title:  " 📷 ", handler: { (ac: UIContextualAction, view: UIView, success:(Bool) -> Void) in
    // ...
})
picture.backgroundColor = .blue


我无法在线找到任何东西来启用或禁用它,我仍然希望它存在,只是不想让用户点击它。这可能吗?

最佳答案

我不确定是否可以立即禁用它,但是作为一种变通办法,您可以使用全局变量来跟踪是否应启用该操作,然后在该操作的处理程序中进行检查:

var isCamActionEnabled = false // declare globally, if you need to set this from outside the current scope
let picture = UIContextualAction(style: .normal, title:  " 📷 ", handler: { (ac: UIContextualAction, view: UIView, success:(Bool) -> Void) in
    guard isCamActionEnabled else { return }
    // ...
})

关于ios - 禁用UIContextualAction,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54828549/

10-12 00:15
查看更多