如何为自定义 UIControl 设置 primaryActionTriggered?

How do I set primaryActionTriggered for a custom UIControl?

我创建了一个自定义 UIControl。最接近的比较是 UIStepper 但它是 UIControl 的子类,因为它完全自定义。

对于大多数 UIControl,您可以使用 primaryActionTriggered 创建目标操作,以避免需要知道哪个操作很重要。我希望我的自定义 UIControl 具有同样的便利性。那么如何将 UIControl.Event.valueChanged 映射到 UIControl.Event.primaryActionTriggered

我认为如果您正在监听 valueChanged 事件,那么您只需要在该事件触发时手动调用 sendActions(for: .primaryActionTriggered)