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
}
3条答案
按热度按时间t1rydlwq1#
您可以使用
enumerateEventHandlers
来执行此操作:qoefvg9y2#
根据jrturton所说的here,您可以将其转换为一个小扩展:
现在,您可以在UIButton上调用
removeAllActions()
来获得相同的效果。lvjbypge3#
为什么不使用
view.isUserInteractionEnabled = false
?它将删除视图的所有交互功能