tvOS: pressesEnded is called intermittently

隐身守侯 提交于 2019-12-11 15:39:39

问题


I am creating a subclass of a UIButton, the reason why I'm trying to intercept the touch is because I cant seem to find another way to receive 'press up' or 'press ended' events for the standard UIButton in tvOS. If I could find a way to do that then I wouldn't need to bother with the solution below.

pressesEnded(_ presses: Set<UIPress>, with event: UIPressesEvent?) doesn't seem to be getting called every time I release the 'select' button on the Apple TV Remote.

pressesBegan(_ presses: Set<UIPress>, with event: UIPressesEvent?) is being called every time without any issues. I've attached my code below. Any ideas what could be causing this issue?

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:


After some more testing it seems that when the 'select' button is released tvOS calls either pressesEnded(_ presses: Set<UIPress>, with event: UIPressesEvent?) OR pressesCancelled(_ presses: Set<UIPress>, with event: UIPressesEvent?).

I found this solution by jumping to the definition of pressesEnded(_ presses: Set<UIPress>, with event: UIPressesEvent?) and finding this comment:

Your responder will receive either pressesEnded:withEvent or pressesCancelled:withEvent: for each press it is handling (those presses it received in pressesBegan:withEvent:).



来源:https://stackoverflow.com/questions/47307963/tvos-pressesended-is-called-intermittently

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