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

Siri Remote's Menu Button not exiting application when UIButton is focused

我正在覆盖 pressesBegan 以接收 Select 新闻。当焦点位于 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)
        }
    }
}

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
}