Skip to content

Commit bc59409

Browse files
authored
Merge pull request #326 from dogo/small-fix
Fix race condition in keyboard hide animation
2 parents cd42986 + 8a01c99 commit bc59409

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

SCLAlertView/SCLAlertView.m

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,8 @@ - (void)keyboardWillHide:(NSNotification *)notification
721721
NSTimeInterval animationDuration = [userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
722722
UIViewAnimationOptions animationCurve = [userInfo[UIKeyboardAnimationCurveUserInfoKey] unsignedIntegerValue] << 16;
723723

724+
_keyboardIsVisible = NO;
725+
724726
[UIView animateWithDuration:animationDuration delay:0 options:animationCurve animations:^{
725727
CGRect contentFrame = self.contentView.frame;
726728
contentFrame.origin.y = self->_tmpContentViewFrameOrigin.y;
@@ -730,11 +732,12 @@ - (void)keyboardWillHide:(NSNotification *)notification
730732
circleFrame.origin.y = self->_tmpCircleViewFrameOrigin.y;
731733
self.circleViewBackground.frame = circleFrame;
732734
} completion:^(BOOL finished) {
733-
self->_tmpContentViewFrameOrigin = CGPointZero;
734-
self->_tmpCircleViewFrameOrigin = CGPointZero;
735+
// Only reset if keyboard hasn't been shown again during the animation
736+
if (!self->_keyboardIsVisible) {
737+
self->_tmpContentViewFrameOrigin = CGPointZero;
738+
self->_tmpCircleViewFrameOrigin = CGPointZero;
739+
}
735740
}];
736-
737-
_keyboardIsVisible = NO;
738741
}
739742
}
740743

0 commit comments

Comments
 (0)