Skip to content

Commit 4a3aada

Browse files
author
Gabor Kovacs
committed
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
1 parent f533c6c commit 4a3aada

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,11 @@ -(void)TPKeyboardAvoiding_scrollToActiveTextField {
154154
CGPoint idealOffset = CGPointMake(0, [self TPKeyboardAvoiding_idealOffsetForView:[self TPKeyboardAvoiding_findFirstResponderBeneathView:self]
155155
withViewingAreaHeight:visibleSpace]);
156156

157-
// Ordinarily we'd use -setContentOffset:animated:YES here, but it does not appear to
158-
// scroll to the desired content offset. So we wrap in our own animation block.
159-
[UIView animateWithDuration:0.25 animations:^{
160-
[self setContentOffset:idealOffset animated:NO];
161-
[self layoutIfNeeded];
162-
}];
157+
// Ordinarily we'd use -setContentOffset:animated:YES here, but it interferes with UIScrollView
158+
// behavior which automatically ensures that the first responder is within its bounds
159+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
160+
[self setContentOffset:idealOffset animated:YES];
161+
});
163162
}
164163

165164
#pragma mark - Helpers

0 commit comments

Comments
 (0)