@@ -170,7 +170,7 @@ - (CGFloat)heightInView:(UIView *)view {
170170 return [self height ];
171171 }
172172 CGRect keyboardRect = [QMUIKeyboardManager convertKeyboardRect: _endFrame toView: view];
173- CGRect visibleRect = CGRectIntersection (view.bounds , keyboardRect);
173+ CGRect visibleRect = CGRectIntersection (CGRectFlatted ( view.bounds ), CGRectFlatted ( keyboardRect) );
174174 if (!CGRectIsValidated (visibleRect)) {
175175 return 0 ;
176176 }
@@ -312,8 +312,14 @@ - (void)addKeyboardNotification {
312312 [[NSNotificationCenter defaultCenter ] addObserver: self selector: @selector (keyboardDidChangeFrameNotification: ) name: UIKeyboardDidChangeFrameNotification object: nil ];
313313}
314314
315- - (BOOL )isAppActive {
316- return [[UIApplication sharedApplication ] applicationState ] == UIApplicationStateActive;
315+ - (BOOL )isAppActive : (NSNotification *)notification {
316+ if ([[UIApplication sharedApplication ] applicationState ] != UIApplicationStateActive) {
317+ return NO ;
318+ }
319+ if (![[notification.userInfo valueForKey: UIKeyboardIsLocalUserInfoKey] boolValue ]) {
320+ return NO ;
321+ }
322+ return YES ;
317323}
318324
319325- (void )keyboardWillShowNotification : (NSNotification *)notification {
@@ -322,7 +328,7 @@ - (void)keyboardWillShowNotification:(NSNotification *)notification {
322328 QMUILog (NSStringFromClass (self.class ), @" keyboardWillShowNotification - %@ " , self);
323329 }
324330
325- if (![self isAppActive ]) {
331+ if (![self isAppActive: notification ]) {
326332 QMUILog (NSStringFromClass (self.class ), @" app is not active" );
327333 return ;
328334 }
@@ -346,7 +352,7 @@ - (void)keyboardDidShowNotification:(NSNotification *)notification {
346352 QMUILog (NSStringFromClass (self.class ), @" keyboardDidShowNotification - %@ " , self);
347353 }
348354
349- if (![self isAppActive ]) {
355+ if (![self isAppActive: notification ]) {
350356 QMUILog (NSStringFromClass (self.class ), @" app is not active" );
351357 return ;
352358 }
@@ -371,7 +377,7 @@ - (void)keyboardWillHideNotification:(NSNotification *)notification {
371377 QMUILog (NSStringFromClass (self.class ), @" keyboardWillHideNotification - %@ " , self);
372378 }
373379
374- if (![self isAppActive ]) {
380+ if (![self isAppActive: notification ]) {
375381 QMUILog (NSStringFromClass (self.class ), @" app is not active" );
376382 return ;
377383 }
@@ -395,7 +401,7 @@ - (void)keyboardDidHideNotification:(NSNotification *)notification {
395401 QMUILog (NSStringFromClass (self.class ), @" keyboardDidHideNotification - %@ " , self);
396402 }
397403
398- if (![self isAppActive ]) {
404+ if (![self isAppActive: notification ]) {
399405 QMUILog (NSStringFromClass (self.class ), @" app is not active" );
400406 return ;
401407 }
@@ -421,7 +427,7 @@ - (void)keyboardWillChangeFrameNotification:(NSNotification *)notification {
421427 QMUILog (NSStringFromClass (self.class ), @" keyboardWillChangeFrameNotification - %@ " , self);
422428 }
423429
424- if (![self isAppActive ]) {
430+ if (![self isAppActive: notification ]) {
425431 QMUILog (NSStringFromClass (self.class ), @" app is not active" );
426432 return ;
427433 }
@@ -448,7 +454,7 @@ - (void)keyboardDidChangeFrameNotification:(NSNotification *)notification {
448454 QMUILog (NSStringFromClass (self.class ), @" keyboardDidChangeFrameNotification - %@ " , self);
449455 }
450456
451- if (![self isAppActive ]) {
457+ if (![self isAppActive: notification ]) {
452458 QMUILog (NSStringFromClass (self.class ), @" app is not active" );
453459 return ;
454460 }
@@ -524,6 +530,7 @@ + (void)animateWithAnimated:(BOOL)animated keyboardUserInfo:(QMUIKeyboardUserInf
524530
525531+ (void )handleKeyboardNotificationWithUserInfo : (QMUIKeyboardUserInfo *)keyboardUserInfo showBlock : (void (^)(QMUIKeyboardUserInfo *keyboardUserInfo))showBlock hideBlock : (void (^)(QMUIKeyboardUserInfo *keyboardUserInfo))hideBlock {
526532 // 专门处理 iPad Pro 在键盘完全不显示的情况(不会调用willShow,所以通过是否focus来判断)
533+ // iPhoneX Max 这里键盘高度不是0,而是一个很小的值
527534 if ([QMUIKeyboardManager visibleKeyboardHeight ] <= 0 && !keyboardUserInfo.isTargetResponderFocused ) {
528535 if (hideBlock) {
529536 hideBlock (keyboardUserInfo);
@@ -613,7 +620,7 @@ + (CGRect)convertKeyboardRect:(CGRect)rect toView:(UIView *)view {
613620
614621+ (CGFloat)distanceFromMinYToBottomInView : (UIView *)view keyboardRect : (CGRect)rect {
615622 rect = [self convertKeyboardRect: rect toView: view];
616- CGFloat distance = CGRectGetHeight (view.bounds ) - CGRectGetMinY (rect);
623+ CGFloat distance = CGRectGetHeight (CGRectFlatted ( view.bounds ) ) - CGRectGetMinY (rect);
617624 return distance;
618625}
619626
@@ -666,7 +673,7 @@ + (BOOL)isKeyboardVisible {
666673 if (!keyboardView || !keyboardWindow) {
667674 return NO ;
668675 }
669- CGRect rect = CGRectIntersection (keyboardWindow.bounds , keyboardView.frame );
676+ CGRect rect = CGRectIntersection (CGRectFlatted ( keyboardWindow.bounds ), CGRectFlatted ( keyboardView.frame ) );
670677 if (CGRectIsValidated (rect) && !CGRectIsEmpty (rect)) {
671678 return YES ;
672679 }
@@ -680,9 +687,9 @@ + (CGRect)currentKeyboardFrame {
680687 }
681688 UIWindow *keyboardWindow = keyboardView.window ;
682689 if (keyboardWindow) {
683- return [keyboardWindow convertRect: keyboardView.frame toWindow: nil ];
690+ return [keyboardWindow convertRect: CGRectFlatted ( keyboardView.frame) toWindow: nil ];
684691 } else {
685- return keyboardView.frame ;
692+ return CGRectFlatted ( keyboardView.frame ) ;
686693 }
687694}
688695
@@ -692,7 +699,7 @@ + (CGFloat)visibleKeyboardHeight {
692699 if (!keyboardView || !keyboardWindow) {
693700 return 0 ;
694701 } else {
695- CGRect visibleRect = CGRectIntersection (keyboardWindow.bounds , keyboardView.frame );
702+ CGRect visibleRect = CGRectIntersection (CGRectFlatted ( keyboardWindow.bounds ), CGRectFlatted ( keyboardView.frame ) );
696703 if (CGRectIsValidated (visibleRect)) {
697704 return CGRectGetHeight (visibleRect);
698705 }
0 commit comments