2012-04-04 51 views
5

可能重复:
How can I detect if an external keyboard is present on an iPad?我怎么知道,如果有一个硬件键盘?

当用户开始编辑在我的iPhone应用程序的UI中的文本框,我想使用文本框和键盘之间的空间相关列表选项。

使用iOS的常规(屏幕上)键盘,有几个convenient notifications要听,这有助于我确定剩下多少空间用于列表中间。

然而,当您连接(或模拟使用的)硬件键盘,这些通知都不再公布。不是太意外,但这给我带来了一些挑战。如果用户使用硬件键盘,我有更多空间用于列表。

但我怎么能确定用户是否有硬件键盘或没有,如果没有触发通知或委托方法来听?或者在那里?

什么也是要考虑的是,用户可以先使用应用程序的软件键盘,然后附上他/她的硬件键盘,并继续与应用工作。此时,软件键盘将隐藏,但用户仍在编辑文本框。

我发现一个老欺骗了这个问题,但没有答案:

回答

3

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

设置你的输入视图的附属视图大小CGRectZero的空UIView。您将收到显示/隐藏通知这两种情况下,并能够从metrics in the notification's userinfo dictionary确定可用的屏幕尺寸。

UIView *inputAccessoryView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease]; 
inputAccessoryView.autoresizingMask = UIViewAutoresizingFlexibleWidth; 
textView.inputAccessoryView = inputAccessoryView; 

… 

- (void)keyboardWillShow:(NSNotification*)aNotification { 
    NSLog(@"%@", [aNotification userInfo]); 
} 

登录指标 - 注意框架UIKeyboardFrameEndUserInfoKey是关闭屏幕

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

更新 - 非常相似,user721239's answer中的相关问题。

+0

尼斯黑客,几乎是一个欺骗的的确是另一个问题,但并没有在我的搜索中显示。谢谢! – epologee 2012-11-08 11:15:12

相关问题