我正在覆盖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)
}
}
}
答案 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
}