如何检测iPad上是否有外接键盘?

如何检测iPad上是否有外接键盘?

有没有办法检测外部(蓝牙或USB)键盘是否连接到iPad?



慕码人2483693
浏览 1070回答 3
3回答

翻过高山走不出你

间接和SDK安全的方法是使文本字段成为第一响应者。如果存在外部键盘,则UIKeyboardWillShowNotification不应发布本地通知。更新:自iOS 9以来不再适用,但您可以使用键盘尺寸来确定是否涉及硬件或软件键盘。您可以收听"GSEventHardwareKeyboardAttached"(kGSEventHardwareKeyboardAvailabilityChangedNotification)Darwin通知,但这是一个私有API,因此如果您使用此应用程序,您的应用程序可能会被拒绝。要检查外部硬件是否存在,请使用私有GSEventIsHardwareKeyboardAttached()功能。UIKit会监听并相应地设置UIKeyboardImpl.isInHardwareKeyboardMode属性,但这又是私有API。

神不在的星期二

if条件确定键盘的底部是否超出self.view的框架。“convertRect”规范化任何方向的框架。- (void)keyboardWillShow:(NSNotification *)notification {keyboardFrame = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];keyboardFrame = [self.view convertRect:keyboardFrame fromView:nil]; // convert orientationkeyboardSize = keyboardFrame.size;//NSLog(@"keyboardFrame.origin.y = %f", keyboardFrame.origin.y);//NSLog(@"keyboardFrame.size.height = %f", keyboardFrame.size.height);BOOL hardwareKeyboardPresent = FALSE;;if ((keyboardFrame.origin.y + keyboardFrame.size.height) > (self.view.frame.size.height+self.navigationController.navigationBar.frame.size.height)) {    hardwareKeyboardPresent = TRUE;}//NSLog(@"bottomOfKeyboard = %f", bottomOfKeyboard);//NSLog(@"self.view.frame.size.height = %f", self.view.frame.size.height);
打开App,查看更多内容
随时随地看视频慕课网APP