@@ -355,50 +355,51 @@ - (void)moveToPoint:(CGPoint)newCenter rotateAngle:(CGFloat)angle {
355355#pragma mark - Master show/dismiss methods
356356
357357- (void )showWithStatus : (NSString *)string maskType : (SVProgressHUDMaskType)hudMaskType networkIndicator : (BOOL )show {
358-
359- if (!self.superview )
360- [self .overlayWindow addSubview: self ];
361-
362- self.fadeOutTimer = nil ;
363-
364- if (self.showNetworkIndicator )
365- [UIApplication sharedApplication ].networkActivityIndicatorVisible = NO ;
366-
367- self.showNetworkIndicator = show;
368-
369- if (self.showNetworkIndicator )
370- [UIApplication sharedApplication ].networkActivityIndicatorVisible = YES ;
358+ dispatch_async ( dispatch_get_main_queue (), ^{
359+ if (!self.superview )
360+ [self .overlayWindow addSubview: self ];
361+
362+ self.fadeOutTimer = nil ;
363+
364+ if (self.showNetworkIndicator )
365+ [UIApplication sharedApplication ].networkActivityIndicatorVisible = NO ;
366+
367+ self.showNetworkIndicator = show;
368+
369+ if (self.showNetworkIndicator )
370+ [UIApplication sharedApplication ].networkActivityIndicatorVisible = YES ;
371371
372- self.imageView .hidden = YES ;
373- self.maskType = hudMaskType;
374-
375- [self setStatus: string];
376- [self .spinnerView startAnimating ];
377-
378- if (self.maskType != SVProgressHUDMaskTypeNone) {
379- self.overlayWindow .userInteractionEnabled = YES ;
380- } else {
381- self.overlayWindow .userInteractionEnabled = NO ;
382- }
383-
384- [self .overlayWindow makeKeyAndVisible ];
385- [self positionHUD: nil ];
386-
387- if (self.alpha != 1 ) {
388- [self registerNotifications ];
389- self.hudView .transform = CGAffineTransformScale (self.hudView .transform , 1.3 , 1.3 );
390-
391- [UIView animateWithDuration: 0.15
392- delay: 0
393- options: UIViewAnimationOptionAllowUserInteraction | UIViewAnimationCurveEaseOut | UIViewAnimationOptionBeginFromCurrentState
394- animations: ^{
395- self.hudView .transform = CGAffineTransformScale (self.hudView .transform , 1 /1.3 , 1 /1.3 );
396- self.alpha = 1 ;
397- }
398- completion: NULL ];
399- }
400-
401- [self setNeedsDisplay ];
372+ self.imageView .hidden = YES ;
373+ self.maskType = hudMaskType;
374+
375+ [self setStatus: string];
376+ [self .spinnerView startAnimating ];
377+
378+ if (self.maskType != SVProgressHUDMaskTypeNone) {
379+ self.overlayWindow .userInteractionEnabled = YES ;
380+ } else {
381+ self.overlayWindow .userInteractionEnabled = NO ;
382+ }
383+
384+ [self .overlayWindow makeKeyAndVisible ];
385+ [self positionHUD: nil ];
386+
387+ if (self.alpha != 1 ) {
388+ [self registerNotifications ];
389+ self.hudView .transform = CGAffineTransformScale (self.hudView .transform , 1.3 , 1.3 );
390+
391+ [UIView animateWithDuration: 0.15
392+ delay: 0
393+ options: UIViewAnimationOptionAllowUserInteraction | UIViewAnimationCurveEaseOut | UIViewAnimationOptionBeginFromCurrentState
394+ animations: ^{
395+ self.hudView .transform = CGAffineTransformScale (self.hudView .transform , 1 /1.3 , 1 /1.3 );
396+ self.alpha = 1 ;
397+ }
398+ completion: NULL ];
399+ }
400+
401+ [self setNeedsDisplay ];
402+ });
402403}
403404
404405
@@ -408,62 +409,63 @@ - (void)dismissWithStatus:(NSString*)string error:(BOOL)error {
408409
409410
410411- (void )dismissWithStatus : (NSString *)string error : (BOOL )error afterDelay : (NSTimeInterval )seconds {
411-
412- if (self.alpha != 1 )
413- return ;
414-
415- if (self.showNetworkIndicator ) {
416- [UIApplication sharedApplication ].networkActivityIndicatorVisible = NO ;
417- self.showNetworkIndicator = NO ;
418- }
419-
420- if (error)
421- self.imageView .image = [UIImage imageNamed: @" SVProgressHUD.bundle/error.png" ];
422- else
423- self.imageView .image = [UIImage imageNamed: @" SVProgressHUD.bundle/success.png" ];
424-
425- self.imageView .hidden = NO ;
426-
427- [self setStatus: string];
428-
429- [self .spinnerView stopAnimating ];
430-
431- self.fadeOutTimer = [NSTimer scheduledTimerWithTimeInterval: seconds target: self selector: @selector (dismiss ) userInfo: nil repeats: NO ];
412+ dispatch_async (dispatch_get_main_queue (), ^{
413+ if (self.alpha != 1 )
414+ return ;
415+
416+ if (self.showNetworkIndicator ) {
417+ [UIApplication sharedApplication ].networkActivityIndicatorVisible = NO ;
418+ self.showNetworkIndicator = NO ;
419+ }
420+
421+ if (error)
422+ self.imageView .image = [UIImage imageNamed: @" SVProgressHUD.bundle/error.png" ];
423+ else
424+ self.imageView .image = [UIImage imageNamed: @" SVProgressHUD.bundle/success.png" ];
425+
426+ self.imageView .hidden = NO ;
427+ [self setStatus: string];
428+ [self .spinnerView stopAnimating ];
429+
430+ self.fadeOutTimer = [NSTimer scheduledTimerWithTimeInterval: seconds target: self selector: @selector (dismiss ) userInfo: nil repeats: NO ];
431+ });
432432}
433433
434434- (void )dismiss {
435-
436- if (self.showNetworkIndicator ) {
437- [UIApplication sharedApplication ].networkActivityIndicatorVisible = NO ;
438- self.showNetworkIndicator = NO ;
439- }
440-
441- [UIView animateWithDuration: 0.15
442- delay: 0
443- options: UIViewAnimationCurveEaseIn | UIViewAnimationOptionAllowUserInteraction
444- animations: ^{
445- self.hudView .transform = CGAffineTransformScale (self.hudView .transform , 0.8 , 0.8 );
446- self.alpha = 0 ;
447- }
448- completion: ^(BOOL finished){
449- if (self.alpha == 0 ) {
450- self.hudView .transform = CGAffineTransformScale (self.hudView .transform , 1.3 /0.8 , 1.3 /0.8 );
451- [[NSNotificationCenter defaultCenter ] removeObserver: self ];
452- [overlayWindow release ], overlayWindow = nil ;
453-
454- // find the frontmost window that is an actual UIWindow and make it keyVisible
455- [[UIApplication sharedApplication ].windows enumerateObjectsWithOptions: NSEnumerationReverse usingBlock: ^(UIWindow *window, NSUInteger idx, BOOL *stop) {
456- if ([window isKindOfClass: [UIWindow class ]] && window.windowLevel == UIWindowLevelNormal) {
435+ dispatch_async (dispatch_get_main_queue (), ^{
436+
437+ if (self.showNetworkIndicator ) {
438+ [UIApplication sharedApplication ].networkActivityIndicatorVisible = NO ;
439+ self.showNetworkIndicator = NO ;
440+ }
441+
442+ [UIView animateWithDuration: 0.15
443+ delay: 0
444+ options: UIViewAnimationCurveEaseIn | UIViewAnimationOptionAllowUserInteraction
445+ animations: ^{
446+ self.hudView .transform = CGAffineTransformScale (self.hudView .transform , 0.8 , 0.8 );
447+ self.alpha = 0 ;
448+ }
449+ completion: ^(BOOL finished){
450+ if (self.alpha == 0 ) {
451+ self.hudView .transform = CGAffineTransformScale (self.hudView .transform , 1.3 /0.8 , 1.3 /0.8 );
452+ [[NSNotificationCenter defaultCenter ] removeObserver: self ];
453+ [overlayWindow release ], overlayWindow = nil ;
454+
455+ // find the frontmost window that is an actual UIWindow and make it keyVisible
456+ [[UIApplication sharedApplication ].windows enumerateObjectsWithOptions: NSEnumerationReverse usingBlock: ^(UIWindow *window, NSUInteger idx, BOOL *stop) {
457+ if ([window isKindOfClass: [UIWindow class ]] && window.windowLevel == UIWindowLevelNormal) {
457458 [window makeKeyWindow ];
458459 *stop = YES ;
459- }
460- }];
461-
462- // uncomment to make sure UIWindow is gone from app.windows
463- // NSLog(@"%@", [UIApplication sharedApplication].windows);
464- // NSLog(@"keyWindow = %@", [UIApplication sharedApplication].keyWindow);
465- }
466- }];
460+ }
461+ }];
462+
463+ // uncomment to make sure UIWindow is gone from app.windows
464+ // NSLog(@"%@", [UIApplication sharedApplication].windows);
465+ // NSLog(@"keyWindow = %@", [UIApplication sharedApplication].keyWindow);
466+ }
467+ }];
468+ });
467469}
468470
469471#pragma mark - Utilities
0 commit comments