【问题标题】:Intercept an event or track an event of custom control in iOs在 iOs 中拦截事件或跟踪自定义控件的事件
【发布时间】:2017-06-01 20:41:24
【问题描述】:

我正在创建一个自定义 UIButton。 所以当一个应用程序使用这个按钮并且显然有一个绑定到它的UIControleventtouchdown 事件的方法时。我想在调用click方法之前做一些操作。

那么是否可以在传递给绑定到UIControleventtouchdown事件的方法之前拦截调用并做一些操作?

【问题讨论】:

  • 你为什么要这个,你想早点做什么?
  • 我想跟踪按钮被启动/渲染和点击的次数。

标签: ios objective-c swift uibutton custom-controls


【解决方案1】:

如果您的 CustomButton 只需覆盖 sendAction(_:to:for:)

class CustomButton: UIButton {
    override func sendAction(_ action: Selector, to target: Any?, for event: UIEvent?) {
        // perform custom operations here
        super.sendAction(action, to: target, for: event)
    }
}

【讨论】:

    猜你喜欢
    • 2011-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多