[英]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.