2017-06-01 67 views
0

我正在創建自定義UIButton。 所以,當一個應用程序使用這個按鈕,顯然有一個方法綁定到它的事件UIControleventtouchdown。我想在調用click方法之前執行特定的操作。攔截事件或跟蹤iOs中的自定義控件事件

那麼是否有可能在傳遞給綁定到UIControleventtouchdown事件的方法之前攔截該調用並執行一些操作?

+0

爲什麼你不想這樣,你想要什麼提早辦? –

+0

我想跟蹤按鈕發起/渲染和點擊的次數。 –

回答

0

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

謝謝你會嘗試這個並更新。 –

+0

真棒這可以作爲魅力!謝謝 :-) –