tvOS:pressEnded被间歇性地调用

时间:2017-11-15 12:53:24

标签: swift uibutton tvos

我正在创建一个UIButton的子类,我试图拦截触摸的原因是因为我似乎无法找到另一种方式来接收'按下'或者'按下结束' tvOS中标准UIButton的事件。如果我能找到一种方法,那么我就不需要为下面的解决方案而烦恼。

每次我发布“选择”时,

pressesEnded(_ presses: Set<UIPress>, with event: UIPressesEvent?)似乎都没有被调用。 Apple TV遥控器上的按钮。

每次都会调用

pressesBegan(_ presses: Set<UIPress>, with event: UIPressesEvent?)而没有任何问题。我在下面附上了我的代码。可能导致此问题的任何想法?

class EVLPTZButton: UIButton
{
  var command: PTZCommand!
  var delegate: EVLPTZButtonCommandDelegate?

  override func pressesBegan(_ presses: Set<UIPress>, with event: UIPressesEvent?)
  {
    super.pressesBegan(presses, with: event)

    delegate?.ptzButton(pressesBeganFor: self, with: command)
  }

  override func pressesEnded(_ presses: Set<UIPress>, with event: UIPressesEvent?)
  {
    super.pressesEnded(presses, with: event)

    delegate?.ptzButton(pressesEndedFor: self)
  }
}

1 个答案:

答案 0 :(得分:1)

经过一些更多的测试后,似乎在选择&#39;按钮已发布tvOS呼叫pressesEnded(_ presses: Set<UIPress>, with event: UIPressesEvent?) pressesCancelled(_ presses: Set<UIPress>, with event: UIPressesEvent?)

我通过跳转到pressesEnded(_ presses: Set<UIPress>, with event: UIPressesEvent?)的定义并找到此评论找到了这个解决方案:

  

您的响应者将收到pressEnded:withEvent或   pressCancelled:withEvent:每次按下它都是处理(那些   按下它在pressBegan中收到:withEvent:)。