或者有没有办法检查 UIControl 是否有任何 UIActions?
有时我想改变 UIControl 的行为。当使用目标动作时,我可以这样做
button.removeTarget(nil, action: nil), for: .touchUpInside)
button.addTarget(self, action: #selector(didTouchUpInside()), for: .for: .touchUpInside)
Run Code Online (Sandbox Code Playgroud)
您可以使用以下方法执行此操作enumerateEventHandlers:
button.enumerateEventHandlers { action, targetAction, event, stop in
if let action = action {
// This is a UIAction
button.removeAction(action, for: event)
}
if let (target, selector) = targetAction {
// This is target / action
button.removeTarget(target, action: selector, for: event)
}
stop = true // Ends iterating early if you are done
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
565 次 |
| 最近记录: |