ios - 拦截事件或跟踪 iO 中自定义控件的事件

标签 ios objective-c swift uibutton custom-controls

我正在创建一个自定义UIButton。 因此,当应用程序使用此按钮时,显然有一个方法绑定(bind)到它的 UIControleventtouchdown 事件。我想在调用click方法之前进行一定的操作。

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

最佳答案

如果您的 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)
    }
}

关于ios - 拦截事件或跟踪 iO 中自定义控件的事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44316743/

相关文章:

ios - 将 UITextField 连接到 SLComposeViewController - swift

ios - 使用照片框架的视频选择器

ios - NSLocalizedString为数字

objective-c - 让 Objective-C 类看起来很漂亮

swift - 我们可以在 Swift 中同时使用 Public 和 Private 访问修饰符吗?

ios - 子类化 MKAnnotation 导致 Set 集合不起作用

ios - 下载 iOS 6 模拟器

c++ - VTK:对齐两个 Actor

iphone - 如何在 iOS 中设置事件指示器 View

objective-c - 在 objective-c 中触摸一个文件