本文介绍了使用UIKeyCommand检测连续按键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以连续按键?
我正在使用 keyCommands :拦截外接键盘上按下的箭头键,但每次按下我只能接听1次。我希望只要按下按键就可以每隔X毫秒进行一次多次通话,或者在按下按键时以及按下按键时调用。
I'm using keyCommands: to intercept the arrows keys being pressed on an external keyboard, but I only get 1 call per press. I would love to get either multiple calls every X milliseconds as long as the key is held down, or calls when the key is pressed and when it’s released.
这是我的代码:
- (NSArray *)keyCommands
{
UIKeyCommand *upArrow = [UIKeyCommand keyCommandWithInput:UIKeyInputUpArrow
modifierFlags:0
action:@selector(upArrow:)];
UIKeyCommand *downArrow = [UIKeyCommand keyCommandWithInput:UIKeyInputDownArrow
modifierFlags:0
action:@selector(downArrow:)];
UIKeyCommand *leftArrow = [UIKeyCommand keyCommandWithInput:UIKeyInputLeftArrow
modifierFlags:0
action:@selector(leftArrow:)];
UIKeyCommand *rightArrow = [UIKeyCommand keyCommandWithInput:UIKeyInputRightArrow
modifierFlags:0
action:@selector(rightArrow:)];
UIKeyCommand *leftArrowCmd = [UIKeyCommand keyCommandWithInput:UIKeyInputLeftArrow
modifierFlags:UIKeyModifierCommand
action:@selector(leftArrowCmd:)];
UIKeyCommand *rightArrowCmd = [UIKeyCommand keyCommandWithInput:UIKeyInputRightArrow
modifierFlags:UIKeyModifierCommand
action:@selector(rightArrowCmd:)];
UIKeyCommand *lCmd = [UIKeyCommand keyCommandWithInput:@"l"
modifierFlags:UIKeyModifierCommand
action:@selector(lCmd:)];
UIKeyCommand *rCmd = [UIKeyCommand keyCommandWithInput:@"r"
modifierFlags:UIKeyModifierCommand
action:@selector(rCmd:)];
UIKeyCommand *mCmd = [UIKeyCommand keyCommandWithInput:@"m"
modifierFlags:UIKeyModifierCommand
action:@selector(mCmd:)];
return @[upArrow, downArrow, leftArrow, rightArrow, leftArrowCmd, rightArrowCmd, lCmd, rCmd, mCmd];
}
推荐答案
似乎这确实不是可以在iOS 7中使用。
Seems that this is indeed not possible in iOS 7.
这篇关于使用UIKeyCommand检测连续按键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!