tvOS - playPause手势无法正常工作

时间:2017-10-17 14:06:07

标签: swift tvos uitapgesturerecognizer tvos10

PlayPause按钮没有响应。
以下是我在viewDidLoad方法中放置的代码:

playPauseTapGestureRegocnizer = UITapGestureRecognizer(target: self, action: #selector(playPauseTapped))
playPauseTapGestureRegocnizer.allowedPressTypes = [NSNumber(value: UIPressType.playPause.rawValue)]
view.addGestureRecognizer(playPauseTapGestureRegocnizer)

我尝试将它放在多个方法中,但它不起作用。
奇怪的是,当我用playPause更改menu时,它与菜单按钮完美配合。

我错过了什么吗?

1 个答案:

答案 0 :(得分:0)

雨燕4

PlayPause手势在实际设备上不起作用。 另一种解决方案是听UIPressesEvent

override func pressesEnded(_ presses: Set<UIPress>, with event: UIPressesEvent?)
{
    for press in presses
    {
        if press.type == UIPress.PressType.playPause
        {
            // handle play pause action
            break
        }
        else
        {
            super.pressesEnded(presses, with: event)
        }
    }
}