当“播放/暂停"按钮被覆盖时,允许"Siri远程菜单"按钮 [英] Allow Siri Remote Menu button when Play/Pause button is overridden

查看:97
本文介绍了当“播放/暂停"按钮被覆盖时,允许"Siri远程菜单"按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(MainController.tapped(_:)))
tapRecognizer.allowedPressTypes = [NSNumber(integer: UIPressType.PlayPause.rawValue)]
self.view.addGestureRecognizer(tapRecognizer)

此代码使我可以覆盖播放/暂停按钮,并且它可以正常工作.但是,现在我必须长按菜单按钮才能返回到Apple TV OS菜单.

This code allows me to override the play/pause button and it works correctly. However, now I have to long press the Menu button to return to the Apple TV OS menu.

无论如何,按下菜单"按钮后,它是否直接返回到OS菜单,而播放/暂停"按钮仍在执行我当前的逻辑?恐怕如果单击菜单"不能返回操作系统菜单,我的应用程序可能会被拒绝.

Is there anyway when the Menu button is pressed, it returns directly to the OS menu while the Play/Pause button keeps doing my current logic? I am afraid if clicking on Menu doesn't return to OS menu, my app could be rejected.

推荐答案

要返回Apple TV主屏幕,可以在viewDidLoad中设置UITapGestureRecognizer,如下所示:

To return to the Apple TV home screen you can setup a UITapGestureRecognizer in your viewDidLoad like so:

// 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您的应用程序:

and then in handleMenuGesture you suspend your application:

// MARK: - Handle Siri Remote Menu Button
func handleMenuGesture(tap: UITapGestureRecognizer) {
    print("Menu Gesture")
    UIControl().sendAction(#selector(NSURLSessionTask.suspend), to: UIApplication.sharedApplication(), forEvent: nil)
}

相关:当UIButton处于焦点状态时,Siri Remote的菜单按钮未退出应用程序

这篇关于当“播放/暂停"按钮被覆盖时,允许"Siri远程菜单"按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆