'Player controller dismiss on press Menu button in tvOS
Now i am working on the tvOS application. This application based on the media type like video play/pause. I want, when am i presenting the video controller for playing the video. Normally the i press menu button the video controller dismiss and redirect to previous screen. While my requirement is that, if the user pause video and press the menu button as for my requirement dismiss the video controller. But in this condition i press menu button two times for dismiss video controller.
I am using this code for dismiss.
override func viewWillAppear(animated: Bool) {
let menuPressRecognizer = UITapGestureRecognizer()
menuPressRecognizer.addTarget(self, action: #selector(VideoPlayerViewController.menuButtonAction(_:)))
menuPressRecognizer.allowedPressTypes = [NSNumber(integer: UIPressType.Menu.rawValue)]
self.playerController.view.addGestureRecognizer(menuPressRecognizer)
}
func menuButtonAction(ges:UITapGestureRecognizer) {
self.dismissView()
}
But it is not working as for requirement. My requirement is menu button press only one time for dismiss view controller.
Solution 1:[1]
func menuButtonAction(ges:UITapGestureRecognizer) {
if player.rate == 0 {
self.dismiss()
} else {
self.player.pause()
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Arasuvel |
