我試圖在用戶單擊Apple TV遙控器上的暫停/播放按鈕時創建操作。我查看了文檔,但Apple推薦的文檔代碼不起作用。以下是我的代碼如下。有人能告訴我我做錯了什麼嗎?需要考慮的事項: 我正在使用AVPlayerMovieController &我的代碼中有另一個手勢識別器,但它是一個輕掃手勢,此方法正在調用,而不是暫停/播放。有人可以幫忙嗎?UITapGestureRecognizer&tvOS遙控器用於暫停/播放按鈕
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
tap.allowedPressTypes = @[[NSNumber numberWithInteger:UIPressTypePlayPause]];
[self.view addGestureRecognizer:tap];
謝謝
如果您的視圖已經在檢測按下按鈕(例如UICollectionViewCell等),它將起作用(無需添加UITapGestureRecognizer)。所有其他條件相同,最簡單的解決方案應該是選定的答案(這一個)。對於其他人,您可以添加點按手勢識別器,並允許按下UIPressType.PlayPause按鈕。請參閱https://developer.apple.com/library/tvos/documentation/General/Conceptual/AppleTV_PG/DetectingButtonPressesandGestures.html – skim