From f533c6ccce171f83c2947a349aa2a77bc82c3af3 Mon Sep 17 00:00:00 2001 From: Gabor Kovacs Date: Fri, 24 Oct 2014 12:44:54 +0200 Subject: [PATCH 1/2] Scrollview stuttering problem on content inset/offset change fixed --- TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m b/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m index 538014b6..11f331e4 100644 --- a/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m +++ b/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m @@ -79,6 +79,7 @@ - (void)TPKeyboardAvoiding_keyboardWillShow:(NSNotification*)notification { } self.scrollIndicatorInsets = self.contentInset; + [self layoutIfNeeded]; [UIView commitAnimations]; } @@ -104,6 +105,7 @@ - (void)TPKeyboardAvoiding_keyboardWillHide:(NSNotification*)notification { self.contentInset = state.priorInset; self.scrollIndicatorInsets = state.priorScrollIndicatorInsets; + [self layoutIfNeeded]; [UIView commitAnimations]; } @@ -156,6 +158,7 @@ -(void)TPKeyboardAvoiding_scrollToActiveTextField { // scroll to the desired content offset. So we wrap in our own animation block. [UIView animateWithDuration:0.25 animations:^{ [self setContentOffset:idealOffset animated:NO]; + [self layoutIfNeeded]; }]; } From 4a3aada6f7a27521dcfbcb9bc46109fda8efb520 Mon Sep 17 00:00:00 2001 From: Gabor Kovacs Date: Sat, 25 Oct 2014 19:52:59 +0200 Subject: [PATCH 2/2] Layouting in animation block during responder change causes weird animations inside the text fields, so it is an another workaround to solve the stuttering problem --- .../UIScrollView+TPKeyboardAvoidingAdditions.m | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m b/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m index 11f331e4..ef52f9d1 100644 --- a/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m +++ b/TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m @@ -154,12 +154,11 @@ -(void)TPKeyboardAvoiding_scrollToActiveTextField { CGPoint idealOffset = CGPointMake(0, [self TPKeyboardAvoiding_idealOffsetForView:[self TPKeyboardAvoiding_findFirstResponderBeneathView:self] withViewingAreaHeight:visibleSpace]); - // Ordinarily we'd use -setContentOffset:animated:YES here, but it does not appear to - // scroll to the desired content offset. So we wrap in our own animation block. - [UIView animateWithDuration:0.25 animations:^{ - [self setContentOffset:idealOffset animated:NO]; - [self layoutIfNeeded]; - }]; + // Ordinarily we'd use -setContentOffset:animated:YES here, but it interferes with UIScrollView + // behavior which automatically ensures that the first responder is within its bounds + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [self setContentOffset:idealOffset animated:YES]; + }); } #pragma mark - Helpers