我在编写iOS游戏(使用SpriteKit),我想用外部键盘控制它。 我试过那段代码:
func DownArrowPress(sender: UIKeyCommand) {
print("Arrow Down Start")
}
func UpArrowPress(sender: UIKeyCommand) {
print("Arrow Up Start")
}
func LeftArrowPress(sender: UIKeyCommand) {
print("Arrow Left Start")
}
func RightArrowPress(sender: UIKeyCommand) {
print("Arrow Right Start")
}
func SpaceKeyPress(sender: UIKeyCommand) {
print("Space Start")
}
override var keyCommands: [UIKeyCommand]? {
return [
UIKeyCommand(input: UIKeyInputDownArrow, modifierFlags: [], action: "DownArrowPress"),
UIKeyCommand(input: UIKeyInputUpArrow, modifierFlags: [], action: "UpArrowPress"),
UIKeyCommand(input: UIKeyInputLeftArrow, modifierFlags: [], action: "UIKeyInputLeftArrow"),
UIKeyCommand(input: UIKeyInputRightArrow, modifierFlags: [], action: "UIKeyInputRightArrow"),
UIKeyCommand(input: " ", modifierFlags: [], action: "SpaceKeyPress")]
}
但现在我有两个问题:
我无法检测到按键的结束!
如果按一个键,没有任何反应......
您有解决问题的想法吗?
感谢您的帮助!