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

大城市里の小女人 提交于 2019-12-11 08:26:43

问题


I made a button. And used the below code. But it doesn't work at all.

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

How can I know when the button is pressed and when button pressing is canceled?


回答1:


Use the built-in UIButton functions - .touchDown, .touchUpInside, .touchUpOutside.

Touch begin:

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

Touch ends:

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


来源:https://stackoverflow.com/questions/41947279/how-to-know-when-the-button-is-pressed-and-canceled-button-pressing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!