3 回答
TA贡献1875条经验 获得超3个赞
间接和SDK安全的方法是使文本字段成为第一响应者。如果存在外部键盘,则UIKeyboardWillShowNotification
不应发布本地通知。
更新:自iOS 9以来不再适用,但您可以使用键盘尺寸来确定是否涉及硬件或软件键盘。
您可以收听"GSEventHardwareKeyboardAttached"
(kGSEventHardwareKeyboardAvailabilityChangedNotification
)Darwin通知,但这是一个私有API,因此如果您使用此应用程序,您的应用程序可能会被拒绝。要检查外部硬件是否存在,请使用私有GSEventIsHardwareKeyboardAttached()
功能。
UIKit会监听并相应地设置UIKeyboardImpl.isInHardwareKeyboardMode
属性,但这又是私有API。
TA贡献1963条经验 获得超6个赞
if条件确定键盘的底部是否超出self.view的框架。“convertRect”规范化任何方向的框架。
- (void)keyboardWillShow:(NSNotification *)notification {
keyboardFrame = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
keyboardFrame = [self.view convertRect:keyboardFrame fromView:nil]; // convert orientation
keyboardSize = 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);
- 3 回答
- 0 关注
- 1069 浏览
添加回答
举报