在IOS 7外接蓝牙键盘整合 [英] External Bluetooth Keyboard integration in IOS 7

查看:727
本文介绍了在IOS 7外接蓝牙键盘整合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要支持我的应用程序外接键盘的功能和需要像Alt + Tab键Tab键组合在应用程序被检测到触发某些事件。在iOS 6中我已经覆盖了

I need to support external keyboard functionality in my app and need key combinations like Alt+Tab Tab to be detected in the app to trigger some event. In IOS 6 I had overridden the

- (void)sendEvent:(UIEvent *)anEvent;

的UIApplication 子类来获得外部键盘上的键pressed组合。

function in the UIApplication subclass to get the key pressed combinations on external keyboard.

但现在我正在测试在IOS 7我的应用程序和的SendEvent甚至不似乎得到所要求的任何硬件密钥pressed事件。

But now I am testing my app in IOS 7 and the sendEvent doesn't even seem to get called for any hardware key pressed event.

任何解决方案..?

推荐答案

有是使用新的<一个来处理键盘快捷键蓝牙键盘上的iOS中7 100%支持的方法href=\"https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIKeyCommand_class/Reference/Reference.html#//apple_ref/occ/cl/UIKeyCommand\"><$c$c>UIKeyCommand类和<一个href=\"https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/event_delivery_responder_chain/event_delivery_responder_chain.html\"><$c$c>UIResponder链。 <一href=\"http://blog.swilliams.me/words/2013/09/19/handling-keyboard-events-with-modifier-keys-in-ios-7\">I没有博客这个的,但这里的要点是:

There is a 100% supported way to handle keyboard shortcuts on a Bluetooth keyboard in iOS 7 using the new UIKeyCommand class and the UIResponder chain. I did blog about this, but here's the gist:

在某处,响应链添加一个方法<一href=\"https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIResponder_Class/Reference/Reference.html#//apple_ref/occ/instp/UIResponder/keyCommands\"><$c$c>keyCommands返回 UIKeyCommand 对象的数组:

Somewhere in your Responder chain add a method for keyCommands that returns an array of UIKeyCommand objects:

- (NSArray *)keyCommands {
    UIKeyCommand *commandF = [UIKeyCommand keyCommandWithInput:@"f" modifierFlags:UIKeyModifierCommand action:@selector(handleCommandF:)];
    return [[NSMutableArray alloc] initWithArray:@[commandF]];
}

然后,当⌘F为pressed(在文字输入视图)响应链会寻找那些 handleCommandF 方法。如果有多个定义,它会用最严密范围一(过的ViewController如:查看本身需要precedence)。

Then, when ⌘F is pressed (in a text input view) the Responder chain will look for that handleCommandF method. If there are multiple definitions, it'll use the most tightly scoped one (eg. the View itself takes precedence over a ViewController).

请注意,当输入(如的UITextField 的UITextView )是第一个响应这只会工作。如果你想在你的应用程序,你可以做,你隐藏的伎俩全球的快捷方式的UITextField 屏幕外,重点关注。

Do note that this will only work when an input (such as UITextField or UITextView) is the first responder. If you want 'global' shortcuts in your app you can do the trick where you hide a UITextField offscreen and focus on that.

这篇关于在IOS 7外接蓝牙键盘整合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆