@@ -385,53 +385,13 @@ - (UIModalPresentationStyle)modalPresentationStyle
385385
386386- (CGFloat)slk_appropriateKeyboardHeight : (NSNotification *)notification
387387{
388- CGFloat keyboardHeight = 0.0 ;
389-
390- CGRect endFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue ];
391-
392388 self.externalKeyboardDetected = [self slk_detectExternalKeyboardInNotification: notification];
393-
394- // Always return 0 if an external keyboard has been detected
395389 if (self.externalKeyboardDetected ) {
396- return keyboardHeight;
397- }
398-
399- // Convert the main screen bounds into the correct coordinate space but ignore the origin
400- CGRect bounds = [self .view convertRect: [UIScreen mainScreen ].bounds fromView: nil ];
401- bounds = CGRectMake (0 , 0 , bounds.size .width , bounds.size .height );
402-
403- // Need to correctly convert the endframe kicked out for iOS 7
404- CGRect endFrameConverted;
405-
406- if (endFrame.size .width == bounds.size .height || endFrame.size .height == bounds.size .width ) {
407- endFrameConverted = SLKRectInvert (endFrame);
408- }
409- else {
410- endFrameConverted = endFrame;
411- }
412-
413- // Sets the minimum height of the keyboard
414- if (self.isMovingKeyboard ) {
415- keyboardHeight = bounds.size .height ;
416- keyboardHeight -= endFrameConverted.origin .y ;
417- }
418- else {
419- if ([notification.name isEqualToString: UIKeyboardWillShowNotification] || [notification.name isEqualToString: UIKeyboardDidShowNotification]) {
420- keyboardHeight = endFrameConverted.size .height ;
421- }
422- else {
423- keyboardHeight = 0.0 ;
424- }
425- }
426-
427- keyboardHeight -= [self slk_appropriateBottomMarginToWindow ];
428- keyboardHeight -= CGRectGetHeight (self.textView .inputAccessoryView .bounds );
429-
430- if (keyboardHeight < 0 || endFrameConverted.origin .y < 0 ) {
431- keyboardHeight = 0.0 ;
390+ return 0.0 ;
432391 }
433392
434- return keyboardHeight;
393+ CGRect endFrame = [self .view convertRect: [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue ] fromView: nil ];
394+ return MAX (0.0 , CGRectGetHeight (self.view .bounds ) - CGRectGetMinY (endFrame) - CGRectGetHeight (self.textView .inputAccessoryView .bounds ));
435395}
436396
437397- (CGFloat)slk_appropriateScrollViewHeight
@@ -470,42 +430,6 @@ - (CGFloat)slk_topBarsHeight
470430 return height;
471431}
472432
473- - (CGFloat)slk_appropriateBottomMarginToWindow
474- {
475- // Converts the main screen bounds into the correct coordinate space, but ignore origin
476- CGRect bounds = [self .view convertRect: [UIScreen mainScreen ].bounds fromView: nil ];
477- bounds = CGRectMake (0 , 0 , bounds.size .width , bounds.size .height );
478-
479- CGRect viewRect = self.view .frame ;
480-
481- CGFloat bottomWindow = CGRectGetMaxY (bounds);
482- CGFloat bottomView = CGRectGetMaxY (viewRect);
483-
484- CGRect statusBarRect = [self .view convertRect: [UIApplication sharedApplication ].statusBarFrame fromView: nil ];
485- CGFloat statusBarHeight = MIN (statusBarRect.size .height , statusBarRect.size .width );
486-
487- CGFloat bottomMargin = bottomWindow - bottomView;
488-
489- if (SLK_IS_IPAD && self.modalPresentationStyle == UIModalPresentationFormSheet) {
490-
491- // Needs to convert the status bar's frame to the correct coordinate space
492- bottomMargin -= statusBarHeight;
493-
494- bottomMargin /= 2.0 ;
495-
496- if (SLK_IS_LANDSCAPE) {
497- bottomMargin += bottomMargin;
498- }
499- else if (SLK_IS_IOS8_AND_HIGHER) {
500- // For some reason in iOS 8 portrait only, we lose half the status bar height somewhere
501- bottomMargin += statusBarHeight/2.0 ;
502- }
503- }
504-
505- // Do NOT consider the status bar's max height gap (40 pts while in-call mode)
506- return (bottomMargin > statusBarHeight) ? bottomMargin : 0.0 ;
507- }
508-
509433- (NSString *)slk_appropriateKeyboardNotificationName : (NSNotification *)notification
510434{
511435 NSString *name = notification.name ;
@@ -1044,7 +968,7 @@ - (void)slk_reloadInputAccessoryViewIfNeeded
1044968 }
1045969 }
1046970 // Reload only if the input views if the frame doesn't match the text input bar's.
1047- else if (self. textView . inputAccessoryView && CGRectGetHeight (self.textView .inputAccessoryView .frame ) != CGRectGetHeight (self.textInputbar .bounds )) {
971+ else if (CGRectGetHeight (self.textView .inputAccessoryView .frame ) != CGRectGetHeight (self.textInputbar .bounds )) {
1048972 self.textView .inputAccessoryView = [self emptyInputAccessoryView ];
1049973 [self .textView refreshInputViews ];
1050974 }
@@ -1217,7 +1141,7 @@ - (void)slk_didShowOrHideKeyboard:(NSNotification *)notification
12171141 // Updates the dismiss mode and input accessory view, if needed.
12181142 [self slk_reloadInputAccessoryViewIfNeeded ];
12191143
1220- // Very important to invalidate this flag after the keyboard is dismissed or presented
1144+ // Very important to invalidate this flag after the keyboard is dismissed or presented, to start with a clean state next time.
12211145 self.movingKeyboard = NO ;
12221146}
12231147
0 commit comments