Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit da19510

Browse files
author
Ignacio Romero Zurbuchen
committed
Merge branch 'macoscope-bugfix/animation-on-push'
2 parents 9078166 + 8ddb757 commit da19510

1 file changed

Lines changed: 21 additions & 8 deletions

File tree

Source/Classes/SLKTextViewController.m

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,9 @@ - (void)slk_willShowOrHideKeyboard:(NSNotification *)notification
13061306
NSInteger curve = [notification.userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue];
13071307
NSTimeInterval duration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
13081308

1309+
CGRect beginFrame = [notification.userInfo[UIKeyboardFrameBeginUserInfoKey] CGRectValue];
1310+
CGRect endFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
1311+
13091312
SLKKeyboardStatus status = [self slk_keyboardStatusForNotification:notification];
13101313

13111314
// Programatically stops scrolling before updating the view constraints (to avoid scrolling glitch).
@@ -1328,14 +1331,24 @@ - (void)slk_willShowOrHideKeyboard:(NSNotification *)notification
13281331
[self slk_postKeyboarStatusNotification:notification];
13291332
}
13301333

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];
1334+
void (^animations)() = ^void() {
1335+
[self slk_scrollToBottomIfNeeded];
1336+
};
1337+
1338+
// Begin and end frames are the same when the keyboard is shown during navigation controller's push animation.
1339+
// The animation happens in window coordinates (slides from right to left) but doesn't in the view controller's view coordinates.
1340+
if (!CGRectEqualToRect(beginFrame, endFrame))
1341+
{
1342+
// 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.
1343+
[self.view slk_animateLayoutIfNeededWithDuration:duration
1344+
bounce:NO
1345+
options:(curve<<16)|UIViewAnimationOptionLayoutSubviews|UIViewAnimationOptionBeginFromCurrentState
1346+
animations:animations
1347+
completion:NULL];
1348+
}
1349+
else {
1350+
animations();
1351+
}
13391352
}
13401353

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

0 commit comments

Comments
 (0)