如何知道何时按下和取消按钮 [英] How to know when the button is pressed and canceled Button pressing

查看:155
本文介绍了如何知道何时按下和取消按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

推荐答案

使用内置的UIButton函数-.touchDown.touchUpInside.touchUpOutside.

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

触摸开始:

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

触摸结束:

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

这篇关于如何知道何时按下和取消按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆