From 8a01c99db4ef476384eb9ba57b0423f18f7e3be9 Mon Sep 17 00:00:00 2001 From: Diogo Autilio Date: Sun, 30 Nov 2025 08:42:19 -0300 Subject: [PATCH] Fix race condition in keyboard hide animation Guard temp value reset in completion block to prevent corruption when keyboard is shown again during hide animation. --- SCLAlertView/SCLAlertView.m | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/SCLAlertView/SCLAlertView.m b/SCLAlertView/SCLAlertView.m index d23146a..5c7db95 100755 --- a/SCLAlertView/SCLAlertView.m +++ b/SCLAlertView/SCLAlertView.m @@ -721,6 +721,8 @@ - (void)keyboardWillHide:(NSNotification *)notification NSTimeInterval animationDuration = [userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]; UIViewAnimationOptions animationCurve = [userInfo[UIKeyboardAnimationCurveUserInfoKey] unsignedIntegerValue] << 16; + _keyboardIsVisible = NO; + [UIView animateWithDuration:animationDuration delay:0 options:animationCurve animations:^{ CGRect contentFrame = self.contentView.frame; contentFrame.origin.y = self->_tmpContentViewFrameOrigin.y; @@ -730,11 +732,12 @@ - (void)keyboardWillHide:(NSNotification *)notification circleFrame.origin.y = self->_tmpCircleViewFrameOrigin.y; self.circleViewBackground.frame = circleFrame; } completion:^(BOOL finished) { - self->_tmpContentViewFrameOrigin = CGPointZero; - self->_tmpCircleViewFrameOrigin = CGPointZero; + // Only reset if keyboard hasn't been shown again during the animation + if (!self->_keyboardIsVisible) { + self->_tmpContentViewFrameOrigin = CGPointZero; + self->_tmpCircleViewFrameOrigin = CGPointZero; + } }]; - - _keyboardIsVisible = NO; } }