在出现的模态视图控制器上按下时,允许菜单按钮退出tvOS应用程序 [英] Allow Menu button to exit tvOS app when pressed on presented modal view controller

查看:82
本文介绍了在出现的模态视图控制器上按下时,允许菜单按钮退出tvOS应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个tvOS应用程序,其中UITabBarController作为主故事板的主要入口点.如果用户未登录,则UITabBarController会模态显示LoginViewController.

I have a tvOS app, with a UITabBarController as the main entry point for the main storyboard. If the user is not logged in, the UITabBarController presents a LoginViewController modally.

当用户按下Siri遥控器上的Menu(菜单)按钮时,系统会自动关闭LoginViewController并显示UITabBarController.我希望该应用程序转而退出tvOS床头板.

When the user presses the Menu button on the Siri remote, the system automatically dismiss the LoginViewController and shows the UITabBarController. I want the app to instead exit to the tvOS headboard.

期望解决方案涉及到UITapGestureRecognizer来覆盖菜单"按钮动作,或者覆盖pressesBegan/pressesTouched,但是我还没有找到解决方案.

Expect the solution to involve either a UITapGestureRecognizer to override the Menu button action, or overriding pressesBegan/pressesTouched, but I haven't found a solution yet.

推荐答案

下面的代码段有效,并且是基于苹果

This following snippet works, and is acceptable behavior based on the expected behavior for a menu button in Apples HIG for Remotes and Interactions

override func viewDidLoad() {
    super.viewDidLoad()

    let tapRecognizer = UITapGestureRecognizer(target: self, action: "tapped")
    tapRecognizer.allowedPressTypes = [NSNumber(integer: UIPressType.Menu.rawValue)];
    self.view.addGestureRecognizer(tapRecognizer)
}

func tapped() {
    exit(EXIT_SUCCESS)
}

这篇关于在出现的模态视图控制器上按下时,允许菜单按钮退出tvOS应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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