【问题标题】:How to know when the button is pressed and canceled Button pressing如何知道何时按下按钮和取消按下按钮
【发布时间】:2017-01-30 23:31:39
【问题描述】:

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

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

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

【问题讨论】:

    标签: swift button touchesbegan touches touchesended


    【解决方案1】:

    使用内置的 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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多