如何处理tvOS遥控器中的菜单按钮操作

如何处理tvOS遥控器中的菜单按钮操作

本文介绍了如何处理tvOS遥控器中的菜单按钮操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序面临着一个奇怪的问题。其实当我提出一个视图控制器播放视频。在视频加载时间用户按下菜单按钮,应用程序将转到后台。虽然我已经覆盖了Menu Button Action。



这是我的代码。

 <$ c $ b $ override func viewWillAppear(animated:Bool){
let menuPressRecognizer = UITapGestureRecognizer()
menuPressRecognizer.addTarget(self,action:#selector(VideoPlayerViewController.menuButtonAction(_ :)))
menuPressUcognizer.allowedPressTypes = [NSNumber(integer:UIPressType.Menu.hashValue)]
self.playerController.view.addGestureRecognizer(menuPressRecognizer)
}

func menuButtonAction(ges:UITapGestureRecognizer) {
self.dismissView()
}


解决方案
$ p
$ b

 重写func viewWillAppear(_ animated:Bool){
super.viewWillAppear(animated)
let menuPressRecognizer = UITapGestureRecognizer()
menuPressRecognizer.addTarget(self,action:#selector(YourViewController.menuButtonAction(recognizer :)) ))
menuPressRecognizer.allowedPressTypes = [NSNumber(value:UIPressType.menu.hashValue)]
self.view.addGestureRecognizer(menuPressRecognizer)
}

func menuButtonAction识别器:UITapGestureRecognizer)
{
self.dismiss(animated:true,completion:nil)
}


I am facing the strange problem with my application. Actually when i am presenting a view controller for play the video. At the video load time user press the menu button the application goes to background. While i have overwrite the Menu Button Action.

This is my code.

override func viewWillAppear(animated: Bool) {
    let menuPressRecognizer = UITapGestureRecognizer()
    menuPressRecognizer.addTarget(self, action: #selector(VideoPlayerViewController.menuButtonAction(_:)))
    menuPressRecognizer.allowedPressTypes = [NSNumber(integer: UIPressType.Menu.hashValue)]
    self.playerController.view.addGestureRecognizer(menuPressRecognizer)
}

func menuButtonAction(ges:UITapGestureRecognizer) {
    self.dismissView()
 }
解决方案

This is my code and working for me.

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    let menuPressRecognizer = UITapGestureRecognizer()
    menuPressRecognizer.addTarget(self, action: #selector(YourViewController.menuButtonAction(recognizer:)))
    menuPressRecognizer.allowedPressTypes = [NSNumber(value: UIPressType.menu.hashValue)]
    self.view.addGestureRecognizer(menuPressRecognizer)
}

func menuButtonAction(recognizer:UITapGestureRecognizer)
{
    self.dismiss(animated: true, completion: nil)
}

这篇关于如何处理tvOS遥控器中的菜单按钮操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 13:00