tvOS:pressesEnded 被间歇性调用 [英] tvOS: pressesEnded is called intermittently

查看:26
本文介绍了tvOS:pressesEnded 被间歇性调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?) 似乎没有在我每次释放 Apple TV Remote 上的选择"按钮时被调用.

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, with event: UIPressesEvent?) 每次都被调用,没有任何问题.我在下面附上了我的代码.任何想法可能导致此问题?

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

推荐答案

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

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?).

我通过跳转到 pressesEnded(_ 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:

您的响应者将收到 pressesEnded:withEvent 或pressesCancelled:withEvent: 对于它正在处理的每次按下(那些按下它在 pressesBegan:withEvent: 中接收到的信息.

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

这篇关于tvOS:pressesEnded 被间歇性调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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