我试图给应用程序和YouTuBe一样的行为,当顶部的TabBar是可见的,用户按下遥控器上的菜单按钮时,应用程序应该退出。
所以我重写了pressesBegan和pressesEnded
override func pressesBegan(presses: Set<UIPress>, withEvent event: UIPressesEvent?) {
}什么都没有,否则无论 pressesEnded中的条件如何,应用程序都会退出
override func pressesEnded(presses: Set<UIPress>, withEvent event: UIPressesEvent?) {
if let type = presses.first?.type where type == .Menu {
if navigationController.viewControllers.count == 1 {
if isTabBarOpen {
super.pressesEnded(presses, withEvent: event)
} else {
self.showTabBar()
self.setNeedsFocusUpdate()
self.updateFocusIfNeeded()
}
}
} else {
super.pressesEnded(presses, withEvent: event)
}
}所以我的问题是在应用程序启动(从终止状态,而不是背景状态),如果我按下遥控器上的菜单按钮,if isTabBarOpen{ super.pressesEnded(presses, withEvent: event) }会被执行,但应用程序永远不会退出,除非我移动焦点。
编辑
我试着把最初的注意力集中在TabBar或RootViewController上
如果你需要更多信息,请告诉我:)谢谢
发布于 2016-02-24 05:01:03
您是否尝试过使用手势识别器来捕捉菜单按钮按下?
// add the hook to detect menu button press
let tap = UITapGestureRecognizer(target: self, action: "menuPressed:")
tap.allowedPressTypes = [NSNumber(integer: UIPressType.Menu.rawValue)]
window.rootViewController?.view.addGestureRecognizer(tap) // add it to your view controller
func menuPressed(gesture: UITapGestureRecognizer){
print("menu press")
}https://stackoverflow.com/questions/35463221
复制相似问题