简体   繁体   English

广播UIKeyboardWillShowNotification时,如何知道是否使用iPad蓝牙键盘?

[英]How do I know if the iPad bluetooth keyboard is used when UIKeyboardWillShowNotification is broadcasted?

The notification UIKeyboardWillShowNotification is correctly broadcasted when a keyboard is available to the user. 当用户可以使用键盘时,可以正确广播通知UIKeyboardWillShowNotification

I have my delegate method invoked when this happens, but how do I know if it is bluetooth keyboard or not ? 发生这种情况时,我会调用我的委托方法,但是如何知道它是否是蓝牙键盘?

thanks 谢谢

UPDATE 更新

[[NSNotificationCenter defaultCenter] addObserver:self
 selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification
 object:nil];

That notification (UIKeyboardWillShowNotification) will NOT be broadcast if a bluetooth keyboard is present unless you have an inputAccessoryView. 如果存在蓝牙键盘,则除非您有inputAccessoryView,否则不会广播该通知(UIKeyboardWillShowNotification)。 That, in fact, is the only way to know. 实际上,这是唯一知道的方法。 If you are using this to adjust views for the software keyboard, you should handle that based on this notification and you will always be ok. 如果您使用它来调整软件键盘的视图,则应根据此通知进行处理,您将永远可以。

Otherwise you can check the keyboard size differences in the userInfo property of the notification. 否则,您可以在通知的userInfo属性中检查键盘大小的差异。

The information is available in the userInfo dictionary, it just requires some manipulation to get what you want. 该信息可在userInfo词典中找到,只需进行一些操作即可获得所需的内容。

NSDictionary *userInfo = [aNotification userInfo];
CGRect startKeyboardRect  = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
CGRect finishKeyboardRect = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];

startKeyboardRect   = [self.view convertRect:startKeyboardRect fromView:self.view.window];
finishKeyboardRect  = [self.view convertRect:finishKeyboardRect  fromView:self.view.window];

CGFloat vertShuffle = startKeyboardRect.origin.y - finishKeyboardRect.origin.y;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检测何时蓝牙键盘与ipad断开连接 - How to detect when Bluetooth keyboard is disconnected from ipad UIKeyboardWillShowNotification,如何区分外部键盘和iOS键盘 - UIKeyboardWillShowNotification, how to differentiate between external and iOS keyboard 连接蓝牙输入设备时显示软键盘(iPad) - display soft keyboard (iPad) when is connected a bluetooth input device 我使用xib在我的自定义键盘中加载inputView。 我想知道当方向改变时如何改变inputView的高度吗? - I used xib to load the inputView in my custom keyboard. I Would like to know how to change height of inputView when orientation changes? 在没有UIKeyboardWillShowNotification的情况下获取键盘大小 - Get keyboard size without UIKeyboardWillShowNotification 当我使用自定义textField.inputView时,UIKeyboardWillShowNotification不起作用 - UIKeyboardWillShowNotification not work when i use custom textField.inputView iPad:如何知道按下iPad键盘的返回键? 请检查图像 - iPad : How to know Return key of iPad keyboard is pressed ? Please check image 如何禁用发布UIKeyboardWillShowNotification? - How to disable posting UIKeyboardWillShowNotification? UIKeyboardWillShowNotification - UIKeyboardWillShowNotification 点击下一个UITextField时,没有UIKeyboardWillShowNotification - No UIKeyboardWillShowNotification when tapping the next UITextField
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM