我正在创建 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/