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

北慕城南 提交于 2019-12-08 01:22:26

问题


I'm overriding pressesBegan to receive Select presses. The Siri Remote's Menu Button does not exit my application when the focus is on a UIButton. If no UI element is focused the Menu Button works as expected.

How do I receive Menu Button presses when the focus is on a 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:


UIButton only responds to the .Select button on the remote. You can catch the menu button using a tap gesture recognizer. For example:

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

Then implement:

func menuPressed() {
    // do something
}


来源:https://stackoverflow.com/questions/37685620/siri-remotes-menu-button-not-exiting-application-when-uibutton-is-focused

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!