Skip to content

Commit 1c076e1

Browse files
committed
Fix issue with layout animation when pushing vc with visible keyboard
1 parent 9078166 commit 1c076e1

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

Source/Classes/SLKTextViewController.m

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,14 +1328,24 @@ - (void)slk_willShowOrHideKeyboard:(NSNotification *)notification
13281328
[self slk_postKeyboarStatusNotification:notification];
13291329
}
13301330

1331-
// Only for this animation, we set bo to bounce since we want to give the impression that the text input is glued to the keyboard.
1332-
[self.view slk_animateLayoutIfNeededWithDuration:duration
1333-
bounce:NO
1334-
options:(curve<<16)|UIViewAnimationOptionLayoutSubviews|UIViewAnimationOptionBeginFromCurrentState
1335-
animations:^{
1336-
[self slk_scrollToBottomIfNeeded];
1337-
}
1338-
completion:NULL];
1331+
CGRect beginFrame = [notification.userInfo[UIKeyboardFrameBeginUserInfoKey] CGRectValue];
1332+
CGRect endFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
1333+
// Begin and end frames are the same when the keyboard is shown during navigation controller's push animation.
1334+
// The animation happens in window coordinates (slides from right to left) but doesn't in the view controller's view coordinates.
1335+
BOOL frameWillChange = !CGRectEqualToRect(beginFrame, endFrame);
1336+
1337+
if (frameWillChange) {
1338+
// Only for this animation, we set bo to bounce since we want to give the impression that the text input is glued to the keyboard.
1339+
[self.view slk_animateLayoutIfNeededWithDuration:duration
1340+
bounce:NO
1341+
options:(curve<<16)|UIViewAnimationOptionLayoutSubviews|UIViewAnimationOptionBeginFromCurrentState
1342+
animations:^{
1343+
[self slk_scrollToBottomIfNeeded];
1344+
}
1345+
completion:NULL];
1346+
} else {
1347+
[self slk_scrollToTopIfNeeded];
1348+
}
13391349
}
13401350

13411351
- (void)slk_didShowOrHideKeyboard:(NSNotification *)notification

0 commit comments

Comments
 (0)