@@ -43,21 +43,21 @@ @interface SIAlertView () <SIAlertViewControllerDelegate>
4343
4444@property (nonatomic , assign , getter = isVisible) BOOL visible;
4545
46- + (SIAlertBackgroundWindow *)sharedBackground ;
4746+ (NSMutableArray *)sharedQueue ;
4847+ (SIAlertView *)currentAlertView ;
48+
4949+ (BOOL )isAnimating ;
5050+ (void )setAnimating : (BOOL )animating ;
51- + (void )removeSharedBackground ;
51+
52+ + (void )showBackground ;
53+ + (void )hideBackgroundAnimated : (BOOL )animated ;
5254
5355@end
5456
5557#pragma mark - SIBackgroundWindow
5658
5759@interface SIAlertBackgroundWindow : UIWindow
5860
59- - (void )show ;
60- - (void )hideAnimated : (BOOL )animated ;
6161
6262@end
6363
@@ -81,29 +81,6 @@ - (id)initWithFrame:(CGRect)frame andStyle:(SIAlertViewBackgroundStyle)style
8181 return self;
8282}
8383
84- - (void )show
85- {
86- [UIView animateWithDuration: 0.3
87- animations: ^{
88- self.alpha = 1 ;
89- }];
90- }
91-
92- - (void )hideAnimated : (BOOL )animated
93- {
94- if (!animated) {
95- [SIAlertView removeSharedBackground ];
96- return ;
97- }
98- [UIView animateWithDuration: 0.3
99- animations: ^{
100- self.alpha = 0 ;
101- }
102- completion: ^(BOOL finished) {
103- [SIAlertView removeSharedBackground ];
104- }];
105- }
106-
10784- (void )drawRect : (CGRect)rect
10885{
10986 CGContextRef context = UIGraphicsGetCurrentContext ();
@@ -664,15 +641,6 @@ - (id)initWithTitle:(NSString *)title andMessage:(NSString *)message
664641
665642#pragma mark -
666643
667- + (SIAlertBackgroundWindow *)sharedBackground
668- {
669- if (!__si_alert_background_window) {
670- __si_alert_background_window = [[SIAlertBackgroundWindow alloc ] initWithFrame: [UIScreen mainScreen ].bounds andStyle: [SIAlertView currentAlertView ].backgroundStyle];
671- [__si_alert_background_window makeKeyAndVisible ];
672- }
673- return __si_alert_background_window;
674- }
675-
676644+ (NSMutableArray *)sharedQueue
677645{
678646 if (!__si_alert_queue) {
@@ -701,10 +669,35 @@ + (void)setAnimating:(BOOL)animating
701669 __si_alert_animating = animating;
702670}
703671
704- + (void )removeSharedBackground
672+ + (void )showBackground
673+ {
674+ if (!__si_alert_background_window) {
675+ __si_alert_background_window = [[SIAlertBackgroundWindow alloc ] initWithFrame: [UIScreen mainScreen ].bounds
676+ andStyle: [SIAlertView currentAlertView ].backgroundStyle];
677+ [__si_alert_background_window makeKeyAndVisible ];
678+ __si_alert_background_window.alpha = 0 ;
679+ [UIView animateWithDuration: 0.3
680+ animations: ^{
681+ __si_alert_background_window.alpha = 1 ;
682+ }];
683+ }
684+ }
685+
686+ + (void )hideBackgroundAnimated : (BOOL )animated
705687{
706- [__si_alert_background_window removeFromSuperview ];
707- __si_alert_background_window = nil ;
688+ if (!animated) {
689+ [__si_alert_background_window removeFromSuperview ];
690+ __si_alert_background_window = nil ;
691+ return ;
692+ }
693+ [UIView animateWithDuration: 0.3
694+ animations: ^{
695+ __si_alert_background_window.alpha = 0 ;
696+ }
697+ completion: ^(BOOL finished) {
698+ [__si_alert_background_window removeFromSuperview ];
699+ __si_alert_background_window = nil ;
700+ }];
708701}
709702
710703#pragma mark - Setters
@@ -761,10 +754,8 @@ - (void)show
761754 [SIAlertView setAnimating: YES ];
762755 [SIAlertView setCurrentAlertView: self ];
763756
764- // transition for background if needed
765- if ([SIAlertView sharedQueue ].count == 1 ) {
766- [[SIAlertView sharedBackground ] show ];
767- }
757+ // transition background
758+ [SIAlertView showBackground ];
768759
769760 self.viewController = [[SIAlertViewController alloc ] initWithNibName: nil bundle: nil ];
770761 self.viewController .alertView = self;
@@ -856,14 +847,16 @@ - (void)dismissAnimated:(BOOL)animated cleanup:(BOOL)cleanup
856847 [self .viewController transitionOutCompletion: dismissComplete];
857848
858849 if ([SIAlertView sharedQueue ].count == 1 ) {
859- [[SIAlertView sharedBackground ] hideAnimated: YES ];
850+ // [[SIAlertView sharedBackground] hideAnimated:YES];
851+ [SIAlertView hideBackgroundAnimated: YES ];
860852 }
861853
862854 } else {
863855 dismissComplete ();
864856
865857 if ([SIAlertView sharedQueue ].count == 0 ) {
866- [[SIAlertView sharedBackground ] hideAnimated: NO ];
858+ // [[SIAlertView sharedBackground] hideAnimated:NO];
859+ [SIAlertView hideBackgroundAnimated: YES ];
867860 }
868861 }
869862}
0 commit comments