Skip to content

Commit 4dcb64e

Browse files
committed
fix tint adjustment mode bug
1 parent 15b7e7c commit 4dcb64e

1 file changed

Lines changed: 14 additions & 18 deletions

File tree

SIAlertView/SIAlertView.m

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@
3636
@interface SIAlertView ()
3737

3838
@property (nonatomic, strong) NSMutableArray *items;
39-
@property (nonatomic, weak) UIWindow *oldKeyWindow;
4039
@property (nonatomic, strong) UIWindow *alertWindow;
41-
@property (nonatomic, assign) UIViewTintAdjustmentMode oldTintAdjustmentMode;
4240
@property (nonatomic, assign, getter = isVisible) BOOL visible;
4341

4442
@property (nonatomic, strong) UILabel *titleLabel;
@@ -288,23 +286,34 @@ + (void)showBackground
288286
animations:^{
289287
__si_alert_background_window.alpha = 1;
290288
}];
289+
290+
UIWindow *mainWindow = [UIApplication sharedApplication].windows[0];
291+
mainWindow.tintAdjustmentMode = UIViewTintAdjustmentModeDimmed;
291292
}
292293
}
293294

294295
+ (void)hideBackgroundAnimated:(BOOL)animated
295296
{
296-
if (!animated) {
297+
void (^completion)(void) = ^{
297298
[__si_alert_background_window removeFromSuperview];
298299
__si_alert_background_window = nil;
300+
301+
UIWindow *mainWindow = [UIApplication sharedApplication].windows[0];
302+
mainWindow.tintAdjustmentMode = UIViewTintAdjustmentModeNormal;
303+
[mainWindow makeKeyWindow];
304+
mainWindow.hidden = NO;
305+
};
306+
307+
if (!animated) {
308+
completion();
299309
return;
300310
}
301311
[UIView animateWithDuration:0.3
302312
animations:^{
303313
__si_alert_background_window.alpha = 0;
304314
}
305315
completion:^(BOOL finished) {
306-
[__si_alert_background_window removeFromSuperview];
307-
__si_alert_background_window = nil;
316+
completion();
308317
}];
309318
}
310319

@@ -454,11 +463,6 @@ - (void)show
454463
return;
455464
}
456465

457-
self.oldKeyWindow = [[UIApplication sharedApplication] keyWindow];
458-
459-
self.oldTintAdjustmentMode = self.oldKeyWindow.tintAdjustmentMode;
460-
self.oldKeyWindow.tintAdjustmentMode = UIViewTintAdjustmentModeDimmed;
461-
462466
if (![[SIAlertView sharedQueue] containsObject:self]) {
463467
[[SIAlertView sharedQueue] addObject:self];
464468
}
@@ -589,14 +593,6 @@ - (void)dismissAnimated:(BOOL)animated cleanup:(BOOL)cleanup
589593
[SIAlertView hideBackgroundAnimated:YES];
590594
}
591595
}
592-
593-
UIWindow *window = self.oldKeyWindow;
594-
window.tintAdjustmentMode = self.oldTintAdjustmentMode;
595-
if (!window) {
596-
window = [UIApplication sharedApplication].windows[0];
597-
}
598-
[window makeKeyWindow];
599-
window.hidden = NO;
600596
}
601597

602598
#pragma mark - Transitions

0 commit comments

Comments
 (0)