问题描述
我正在尝试在用户单击 Apple TV Remote 上的暂停/播放按钮时创建一个操作.我查看了文档,但 Apple 文档推荐的代码不起作用.下面是我的代码.有人可以告诉我我做错了什么吗?需要考虑的事项:我正在使用 AVPlayerMovieController &我的代码中确实有另一个手势识别器,但因为它是一个滑动手势,并且正在调用此方法,而不是暂停/播放.有人可以帮忙吗?
I am trying to create an action when a user clicks the pause/play button on the Apple TV Remote. I looked at the documentation, but the code Apple's documentation recommended does not work. Here is my code below. Could someone please tell me what I am doing wrong? Things to consider:I am using an AVPlayerMovieController & I do have another gesture recognizer in my code but for it is a swipe gesture AND this method is getting called, just not the Pause/Play. Can someone please help?
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
tap.allowedPressTypes = @[[NSNumber numberWithInteger:UIPressTypePlayPause]];
[self.view addGestureRecognizer:tap];
谢谢
推荐答案
您可以覆盖 pressesEnded 方法:
You can override the pressesEnded method:
override func pressesEnded(presses: Set<UIPress>, withEvent event: UIPressesEvent?) {
for press in presses {
if(press.type == UIPressType.PlayPause) {
// Do what you want
// ...
} else {
super.pressesEnded(presses, withEvent: event)
}
}
}
这篇关于UITapGestureRecognizer &用于暂停/播放按钮的 tvOS 遥控器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!