我试图检测用户何时按下遥控器上的播放/暂停按钮。我创建了一个点击手势识别器并将其附加到 AVPlayerViewController 子类的视图中。
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(togglePlayPause:)];
tapGestureRecognizer.allowedPressTypes = @[@(UIPressTypePlayPause)];
[self.view addGestureRecognizer:tapGestureRecognizer];
- (void)togglePlayPause:(UITapGestureRecognizer *)tapGestureRecognizer
{
NSLog(@"Toggle play/pause");
if ([self playing])
{
NSLog(@" Pause");
[self.player pause];
}
else
{
NSLog(@" Play");
[self.player play];
}
}
当按下“播放”按钮时,手势可以正常触发,但在按下“暂停”按钮时不会。任何想法为什么?