iOS Swift蓝牙键盘按键检测
答
对不起,我太晚了,我只是意识到我可以帮助你。
你需要使用的是UIKeyCommand。检查了这一点:http://nshipster.com/uikeycommand/
需要注意的是,检测箭头按键,你需要input: UIKeyInputLeftArrow
而不是input: "j"
时显示出来(或当量)。你也不想修饰符(所以用户不必按CMD-左箭头键):请参考Key Commands with no modifier flags—Swift 2。
基本上,你会想(外)您的viewDidLoad后沿此线的东西:
override func canBecomeFirstResponder() -> Bool {
return true
}
override var keyCommands: [UIKeyCommand]? {
return [
UIKeyCommand(input: UIKeyInputDownArrow, modifierFlags: [], action: "DownArrowPress:"),
UIKeyCommand(input: UIKeyInputUpArrow, modifierFlags: [], action: "UpArrowPress:"),
UIKeyCommand(input: " ", modifierFlags: [], action: "SpaceKeyPress:")]
}
// ...
func DownArrowPress(sender: UIKeyCommand) {
// this happens when you press the down arrow.
}
func UpArrowPress(sender: UIKeyCommand) {
// this happens when you press the up arrow.
}
func SpaceKeyPress(sender: UIKeyCommand) {
// this happens when you press the space key.
}
我希望这可以帮助,如果你需要更多的帮助,或发表评论的东西回来@owlswipe是不正确的。