我如何知道是否有硬件键盘?

epo*_*gee 6 keyboard cocoa-touch objective-c ios

可能重复:
如何检测iPad上是否存在外接键盘?

当用户开始在我的iPhone应用程序的UI中编辑文本字段时,我想使用文本字段和键盘之间的空格来获取相关选项的列表.

使用iOS上的常规(屏幕上)键盘,有几个方便的通知可以收听,这有助于我决定我在列表之间剩下多少空间.

但是,当您附加(或模拟使用)硬件键盘时,这些通知不再发布.不出意外,但这给我带来了一些挑战.如果用户使用硬件键盘,我有更多的空间用于列表.

但是,如果没有触发通知或委托方法来监听,我如何确定用户是否有硬件键盘?还是有吗?

还需要考虑的是,用户可以先使用软件键盘使用该应用程序,然后连接他/她的硬件键盘并继续使用该应用程序.此时,软件键盘将隐藏,但用户仍在编辑文本字段.

我找到了这个问题的一个老骗子,但没有答案:

mrw*_*ker 3

如果连接了硬件键盘,输入附件视图将显示在屏幕底部(否则它们将连接到屏幕键盘的顶部)。

\n\n

将输入视图的附件视图设置为空UIView的 size CGRectZero。您将收到这两种情况的显示/隐藏通知,并能够根据通知的 userinfo 字典中的指标确定可用的屏幕尺寸。

\n\n
UIView *inputAccessoryView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];\ninputAccessoryView.autoresizingMask = UIViewAutoresizingFlexibleWidth;\ntextView.inputAccessoryView = inputAccessoryView;\n\n\xe2\x80\xa6\n\n- (void)keyboardWillShow:(NSNotification*)aNotification {\n  NSLog(@"%@", [aNotification userInfo]);\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

记录的指标 - 请注意,其中的帧UIKeyboardFrameEndUserInfoKey不在屏幕上

\n\n
// (NSDictionary *) {\n//     UIKeyboardAnimationCurveUserInfoKey = 0;\n//     UIKeyboardAnimationDurationUserInfoKey = "0.25";\n//     UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {768, 264}}";\n//     UIKeyboardCenterBeginUserInfoKey = "NSPoint: {384, 891}";\n//     UIKeyboardCenterEndUserInfoKey = "NSPoint: {384, 1155}";\n//     UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 758}, {768, 264}}";\n//     UIKeyboardFrameChangedByUserInteraction = 0;\n//     UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 1022}, {768, 264}}";\n// }\n
Run Code Online (Sandbox Code Playgroud)\n\n

更新 - 与user721239在相关问题中的回答非常相似。

\n