let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(MainController.tapped(_:)))
tapRecognizer.allowedPressTypes = [NSNumber(integer: UIPressType.PlayPause.rawValue)]
self.view.addGestureRecognizer(tapRecognizer)
此代码允许我覆盖播放/暂停按钮,它可以正常工作。但是,现在我必须长按Menu(菜单)按钮才能返回Apple TV OS菜单。
无论如何,当按下菜单按钮时,它会直接返回到操作系统菜单,同时播放/暂停按钮会保持当前的逻辑?我担心如果单击菜单没有返回操作系统菜单,我的应用程序可能会被拒绝。
答案 0 :(得分:3)
要返回Apple TV主屏幕,您可以在UITapGestureRecognizer
中设置viewDidLoad
,如下所示:
// Setup Menu Button recognizer
let menuGesture = UITapGestureRecognizer(target: self, action: #selector(ViewController.handleMenuGesture(_:)))
menuGesture.allowedPressTypes = [NSNumber(integer: UIPressType.Menu.rawValue)]
self.view.addGestureRecognizer(menuGesture)
然后在handleMenuGesture
你suspend
你的申请中:
// MARK: - Handle Siri Remote Menu Button
func handleMenuGesture(tap: UITapGestureRecognizer) {
print("Menu Gesture")
UIControl().sendAction(#selector(NSURLSessionTask.suspend), to: UIApplication.sharedApplication(), forEvent: nil)
}
相关:Siri Remote's Menu Button not exiting application when UIButton is focused