3 回答

TA貢獻1875條經(jīng)驗 獲得超3個贊
間接和SDK安全的方法是使文本字段成為第一響應者。如果存在外部鍵盤,則UIKeyboardWillShowNotification
不應發(fā)布本地通知。
更新:自iOS 9以來不再適用,但您可以使用鍵盤尺寸來確定是否涉及硬件或軟件鍵盤。
您可以收聽"GSEventHardwareKeyboardAttached"
(kGSEventHardwareKeyboardAvailabilityChangedNotification
)Darwin通知,但這是一個私有API,因此如果您使用此應用程序,您的應用程序可能會被拒絕。要檢查外部硬件是否存在,請使用私有GSEventIsHardwareKeyboardAttached()
功能。
UIKit會監(jiān)聽并相應地設置UIKeyboardImpl.isInHardwareKeyboardMode
屬性,但這又是私有API。

TA貢獻1963條經(jīng)驗 獲得超6個贊
if條件確定鍵盤的底部是否超出self.view的框架。“convertRect”規(guī)范化任何方向的框架。
- (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 關注
- 1137 瀏覽
添加回答
舉報