当UIButton聚焦时,Siri Remote的菜单按钮不会退出应用程序

时间:2016-06-07 17:26:30

标签: swift tvos apple-tv siri-remote

我正在覆盖pressesBegan以接收选择印刷机。当焦点位于UIButton时,Siri Remote的菜单按钮不会退出我的应用程序。如果没有聚焦UI元素,菜单按钮将按预期工作。

当焦点位于UIButton时,如何按下菜单按钮?

override func pressesBegan(presses: Set<UIPress>, withEvent event: UIPressesEvent?) {
    for item in presses {
        if item.type == .Select {
            print("Click")
        }
        if item.type == .Menu {
            print("Menu Button")
            super.pressesBegan(presses, withEvent: event)
        }
    }
}

1 个答案:

答案 0 :(得分:2)

UIButton仅响应遥控器上的.Select按钮。您可以使用点击手势识别器捕捉菜单按钮。例如:

let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(ClassName.menuPressed()))
tapRecognizer.allowedPressTypes = [NSNumber(integer: UIPressType.Menu.rawValue)];
view.addGestureRecognizer(tapRecognizer)

然后执行:

func menuPressed() {
    // do something
}