如何在 Apple tvOS 上自定义返回导航? [英] How to customize back navigation on Apple tvOS?
问题描述
我正在为 tvOS 开发应用程序.在我的应用程序中,用户分别在不同的视图控制器中选择他们的国家、州和地区.选择后,App 会显示一个页面,其中包含与用户选择相关的信息.当用户按下此页面中的菜单按钮时,我希望应用程序退出,但应用程序转到上一页,即区域选择视图控制器.
I am developing an application for tvOS. In my app users select their country, states and districts respectively in different view controllers. After selections, App displays a page with the information related to users' selections. When user presses the menu button in this page, I want the app to exit, but the app goes to previous page which is district selection view controller.
在这种情况下如何让应用退出.我不希望用户返回所有页面以退出应用程序.
How can I make the app exit in this situation. I don't want user to go back all the pages to exit the app.
推荐答案
我从 这个 问题 DanielStorm 提到.这是快速代码:
I found the solution from this question that Daniel Storm mentioned. Here is the swift code:
override func viewDidLoad(){
let tapRecognizer = UITapGestureRecognizer(target: self, action: "handleTap:")
tapRecognizer.allowedPressTypes = [NSNumber(integer: UIPressType.Menu.rawValue)]
self.view.addGestureRecognizer(tapRecognizer)
}
func handleTap(gesture: UITapGestureRecognizer){
if gesture.state == UIGestureRecognizerState.Ended {
let app = UIApplication.sharedApplication()
app.performSelector(Selector("suspend"))
}
}
希望对大家有所帮助.
这篇关于如何在 Apple tvOS 上自定义返回导航?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!