Skip to content

Commit

Permalink
- Fixed #1568 where setting scrollView contentInset was leading to so…
Browse files Browse the repository at this point in the history
…me gap at the bottom due to safeAreaInsets not taken into consideration.
  • Loading branch information
hackiftekhar committed Sep 25, 2019
1 parent c7d5a36 commit 1e44276
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ @interface TableViewInContainerViewController ()<UIPopoverPresentationController

@implementation TableViewInContainerViewController

-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.view endEditing:YES];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
Expand Down
18 changes: 15 additions & 3 deletions IQKeyboardManager/IQKeyboardManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -1040,10 +1040,15 @@ -(void)adjustPosition
CGFloat bottom = (kbSize.height-keyboardDistanceFromTextField)-(CGRectGetHeight(keyWindow.frame)-CGRectGetMaxY(lastScrollViewRect));

// Update the insets so that the scroll vew doesn't shift incorrectly when the offset is near the bottom of the scroll view.
CGFloat bottomInset = MAX(_startingContentInsets.bottom, bottom);

if (@available(iOS 11, *)) {
bottomInset -= strongLastScrollView.safeAreaInsets.bottom;
}

UIEdgeInsets movedInsets = strongLastScrollView.contentInset;
movedInsets.bottom = bottomInset;

movedInsets.bottom = MAX(_startingContentInsets.bottom, bottom);

if (UIEdgeInsetsEqualToEdgeInsets(strongLastScrollView.contentInset, movedInsets) == NO)
{
[self showLog:[NSString stringWithFormat:@"old ContentInset : %@ new ContentInset : %@", NSStringFromUIEdgeInsets(strongLastScrollView.contentInset), NSStringFromUIEdgeInsets(movedInsets)]];
Expand Down Expand Up @@ -1108,8 +1113,15 @@ -(void)adjustPosition
}
}

CGFloat bottomInset = self.textFieldView.frame.size.height-textViewHeight;

if (@available(iOS 11, *)) {
bottomInset -= self.textFieldView.safeAreaInsets.bottom;
}

UIEdgeInsets newContentInset = textView.contentInset;
newContentInset.bottom = self.textFieldView.frame.size.height-textViewHeight;
newContentInset.bottom = bottomInset;

self.isTextViewContentInsetChanged = YES;

if (UIEdgeInsetsEqualToEdgeInsets(textView.contentInset, newContentInset) == NO)
Expand Down
18 changes: 16 additions & 2 deletions IQKeyboardManagerSwift/IQKeyboardManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1255,10 +1255,18 @@ Codeless drop-in universal library allows to prevent issues of keyboard sliding
let bottom: CGFloat = (kbSize.height-newKeyboardDistanceFromTextField)-(window.frame.height-lastScrollViewRect.maxY)

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

movedInsets.bottom = max(_startingContentInsets.bottom, bottom)
var bottomInset = max(_startingContentInsets.bottom, bottom)

#if swift(>=4.0)
if #available(iOS 11, *) {
bottomInset -= lastScrollView.safeAreaInsets.bottom
}
#endif

var movedInsets = lastScrollView.contentInset
movedInsets.bottom = bottomInset

if lastScrollView.contentInset != movedInsets {
showLog("old ContentInset: \(lastScrollView.contentInset) new ContentInset: \(movedInsets)")

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

#if swift(>=4.0)
if #available(iOS 11, *) {
newContentInset.bottom -= textView.safeAreaInsets.bottom
}
#endif

if textView.contentInset != newContentInset {
self.showLog("\(textFieldView) Old UITextView.contentInset: \(textView.contentInset) New UITextView.contentInset: \(newContentInset)")

Expand Down

0 comments on commit 1e44276

Please sign in to comment.