如何知道按钮何时被按下和取消 Button pressing

How to know when the button is pressed and canceled Button pressing

我做了一个按钮。并使用了下面的代码。 但它根本不起作用。

override func pressesBegan(_ presses: Set<UIPress>, with event: UIPressesEvent?) {
    print("pressTest")
    btnConvert.isHidden = true
}

我如何知道何时按下按钮以及何时取消按下按钮?

使用 built-in UIButton 函数 - .touchDown.touchUpInside.touchUpOutside

触摸开始:

myButton.addTarget(target, action: action, for: .touchDown)

触摸结束:

myButton.addTarget(target, action: action, for: .touchUpInside)
myButton.addTarget(target, action: action, for: .touchUpOutside)