@@ -385,53 +385,13 @@ - (UIModalPresentationStyle)modalPresentationStyle
385
385
386
386
- (CGFloat )slk_appropriateKeyboardHeight : (NSNotification *)notification
387
387
{
388
- CGFloat keyboardHeight = 0.0 ;
389
-
390
- CGRect endFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue ];
391
-
392
388
self.externalKeyboardDetected = [self slk_detectExternalKeyboardInNotification: notification];
393
-
394
- // Always return 0 if an external keyboard has been detected
395
389
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 ;
432
391
}
433
392
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 ));
435
395
}
436
396
437
397
- (CGFloat )slk_appropriateScrollViewHeight
@@ -470,42 +430,6 @@ - (CGFloat)slk_topBarsHeight
470
430
return height;
471
431
}
472
432
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
-
509
433
- (NSString *)slk_appropriateKeyboardNotificationName : (NSNotification *)notification
510
434
{
511
435
NSString *name = notification.name ;
@@ -1044,7 +968,7 @@ - (void)slk_reloadInputAccessoryViewIfNeeded
1044
968
}
1045
969
}
1046
970
// 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 )) {
1048
972
self.textView .inputAccessoryView = [self emptyInputAccessoryView ];
1049
973
[self .textView refreshInputViews ];
1050
974
}
@@ -1217,7 +1141,7 @@ - (void)slk_didShowOrHideKeyboard:(NSNotification *)notification
1217
1141
// Updates the dismiss mode and input accessory view, if needed.
1218
1142
[self slk_reloadInputAccessoryViewIfNeeded ];
1219
1143
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.
1221
1145
self.movingKeyboard = NO ;
1222
1146
}
1223
1147
0 commit comments