swift - tvOS:间歇性调用 pressesEnded

标签 swift uibutton tvos

我正在创建 UIButton 的子类,我试图拦截触摸的原因是因为我似乎无法找到另一种方法来接收 tvOS 中标准 UIButton 的“按下”或“按下结束”事件.如果我能找到一种方法来做到这一点,那么我就不需要为下面的解决方案费心了。

pressesEnded(_ presses: Set<UIPress>, with event: UIPressesEvent?)每次我松开 Apple TV Remote 上的“选择”按钮时似乎都不会被调用。

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)
  }
}

最佳答案

经过更多测试后,似乎当“选择”按钮被释放时,tvOS 会调用 pressesEnded(_ presses: Set<UIPress>, with event: UIPressesEvent?) pressesCancelled(_ presses: Set<UIPress>, with event: UIPressesEvent?) .

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

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

关于swift - tvOS:间歇性调用 pressesEnded,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47307963/

相关文章:

swift - UICollectionView 水平滚动与静态焦点项目

swift - 使用现有的 Web 应用程序创建 Apple TV 应用程序

ios - 如何在 Swift 的 UIAlertView 中调整附件 View 的大小

ios - 如何使用 UIButton 停止特定功能?

ios - 提取 NSDate() 的值

ios - UIbutton 忘记宽度和高度

错误按钮上的 iOS 标题

ios - 如何在 Swift 中使用 MarqueeLabel?

ios - 添加 SKPhysicsJointLimit 后 SKPhysicsBodies 不会发生碰撞

ios - 在自定义键盘上获取键盘高度为 0