Skip to content

Commit 1e44276

Browse files
committed
- Fixed #1568 where setting scrollView contentInset was leading to some gap at the bottom due to safeAreaInsets not taken into consideration.
1 parent c7d5a36 commit 1e44276

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

Demo/Objective_C_Demo/ViewController/TableViewInContainerViewController.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ @interface TableViewInContainerViewController ()<UIPopoverPresentationController
1414

1515
@implementation TableViewInContainerViewController
1616

17+
-(void)viewWillDisappear:(BOOL)animated
18+
{
19+
[super viewWillDisappear:animated];
20+
[self.view endEditing:YES];
21+
}
22+
1723
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
1824
{
1925
return 1;

IQKeyboardManager/IQKeyboardManager.m

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,10 +1040,15 @@ -(void)adjustPosition
10401040
CGFloat bottom = (kbSize.height-keyboardDistanceFromTextField)-(CGRectGetHeight(keyWindow.frame)-CGRectGetMaxY(lastScrollViewRect));
10411041

10421042
// Update the insets so that the scroll vew doesn't shift incorrectly when the offset is near the bottom of the scroll view.
1043+
CGFloat bottomInset = MAX(_startingContentInsets.bottom, bottom);
1044+
1045+
if (@available(iOS 11, *)) {
1046+
bottomInset -= strongLastScrollView.safeAreaInsets.bottom;
1047+
}
1048+
10431049
UIEdgeInsets movedInsets = strongLastScrollView.contentInset;
1050+
movedInsets.bottom = bottomInset;
10441051

1045-
movedInsets.bottom = MAX(_startingContentInsets.bottom, bottom);
1046-
10471052
if (UIEdgeInsetsEqualToEdgeInsets(strongLastScrollView.contentInset, movedInsets) == NO)
10481053
{
10491054
[self showLog:[NSString stringWithFormat:@"old ContentInset : %@ new ContentInset : %@", NSStringFromUIEdgeInsets(strongLastScrollView.contentInset), NSStringFromUIEdgeInsets(movedInsets)]];
@@ -1108,8 +1113,15 @@ -(void)adjustPosition
11081113
}
11091114
}
11101115

1116+
CGFloat bottomInset = self.textFieldView.frame.size.height-textViewHeight;
1117+
1118+
if (@available(iOS 11, *)) {
1119+
bottomInset -= self.textFieldView.safeAreaInsets.bottom;
1120+
}
1121+
11111122
UIEdgeInsets newContentInset = textView.contentInset;
1112-
newContentInset.bottom = self.textFieldView.frame.size.height-textViewHeight;
1123+
newContentInset.bottom = bottomInset;
1124+
11131125
self.isTextViewContentInsetChanged = YES;
11141126

11151127
if (UIEdgeInsetsEqualToEdgeInsets(textView.contentInset, newContentInset) == NO)

IQKeyboardManagerSwift/IQKeyboardManager.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,10 +1255,18 @@ Codeless drop-in universal library allows to prevent issues of keyboard sliding
12551255
let bottom: CGFloat = (kbSize.height-newKeyboardDistanceFromTextField)-(window.frame.height-lastScrollViewRect.maxY)
12561256

12571257
// Update the insets so that the scroll vew doesn't shift incorrectly when the offset is near the bottom of the scroll view.
1258-
var movedInsets = lastScrollView.contentInset
12591258

1260-
movedInsets.bottom = max(_startingContentInsets.bottom, bottom)
1259+
var bottomInset = max(_startingContentInsets.bottom, bottom)
12611260

1261+
#if swift(>=4.0)
1262+
if #available(iOS 11, *) {
1263+
bottomInset -= lastScrollView.safeAreaInsets.bottom
1264+
}
1265+
#endif
1266+
1267+
var movedInsets = lastScrollView.contentInset
1268+
movedInsets.bottom = bottomInset
1269+
12621270
if lastScrollView.contentInset != movedInsets {
12631271
showLog("old ContentInset: \(lastScrollView.contentInset) new ContentInset: \(movedInsets)")
12641272

@@ -1327,6 +1335,12 @@ Codeless drop-in universal library allows to prevent issues of keyboard sliding
13271335
var newContentInset = textView.contentInset
13281336
newContentInset.bottom = textView.frame.size.height-textViewHeight
13291337

1338+
#if swift(>=4.0)
1339+
if #available(iOS 11, *) {
1340+
newContentInset.bottom -= textView.safeAreaInsets.bottom
1341+
}
1342+
#endif
1343+
13301344
if textView.contentInset != newContentInset {
13311345
self.showLog("\(textFieldView) Old UITextView.contentInset: \(textView.contentInset) New UITextView.contentInset: \(newContentInset)")
13321346

0 commit comments

Comments
 (0)