@@ -301,7 +301,7 @@ - (void)show:(BOOL)animated
301
301
[self setNeedsDisplay ];
302
302
303
303
onScreen = YES ;
304
-
304
+
305
305
// Animate the HUD on screen
306
306
CABasicAnimation *fadeAnimation = [CABasicAnimation animationWithKeyPath: @" opacity" ];
307
307
fadeAnimation.duration = _animationDuration;
@@ -329,7 +329,7 @@ - (void)show:(BOOL)animated
329
329
{
330
330
positionAnimation.fromValue = [NSValue valueWithCGPoint: _animationPoint];
331
331
}
332
-
332
+
333
333
positionAnimation.toValue = [NSValue valueWithCGPoint: backgroundView.layer.position];
334
334
positionAnimation.removedOnCompletion = YES ;
335
335
@@ -350,15 +350,15 @@ - (void)hide:(BOOL)animated
350
350
fadeAnimation.fromValue = [NSNumber numberWithFloat: 1.0 ];
351
351
fadeAnimation.toValue = [NSNumber numberWithFloat: 0.0 ];
352
352
fadeAnimation.removedOnCompletion = YES ;
353
-
353
+
354
354
[self .layer addAnimation: fadeAnimation forKey: @" fadeAnimation" ];
355
355
self.layer .opacity = 0.0 ;
356
356
357
357
CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath: @" transform.scale" ];
358
358
scaleAnimation.fromValue = [NSNumber numberWithFloat: 1.0 ];
359
359
scaleAnimation.toValue = [NSNumber numberWithFloat: 0.0 ];
360
360
scaleAnimation.removedOnCompletion = YES ;
361
-
361
+
362
362
CABasicAnimation *frameAnimation = [CABasicAnimation animationWithKeyPath: @" position" ];
363
363
364
364
if (_animationCentered)
@@ -407,7 +407,7 @@ - (void)unregisterFromNotificationCenter {
407
407
408
408
- (void )deviceOrientationDidChange : (NSNotification *)notification {
409
409
UIDeviceOrientation deviceOrientation = [notification.object orientation ];
410
-
410
+
411
411
if (_shouldAutorotate && UIDeviceOrientationIsValidInterfaceOrientation (deviceOrientation)) {
412
412
if (UIDeviceOrientationIsPortrait (deviceOrientation)) {
413
413
if (deviceOrientation == UIDeviceOrientationPortraitUpsideDown) {
@@ -556,7 +556,7 @@ - (void)layoutHUD
556
556
}
557
557
558
558
backgroundRect.origin .x = (self.bounds .size .width / 2.0 ) - (backgroundRect.size .width / 2.0 );
559
- backgroundRect.origin .y = (self.bounds .size .height / 2.0 ) - (_minimumSize.height / 2.0 );
559
+ backgroundRect.origin .y = (self.bounds .size .height / 2.0 ) - (_minimumSize.height / 2.0 );
560
560
561
561
// There is no status label text, center the progress view
562
562
progressRect.origin .x = (backgroundRect.size .width / 2.0 ) - (progressRect.size .width / 2.0 );
@@ -696,6 +696,11 @@ - (void)drawMask
696
696
// Create the gradient as an image, and then set it as the color of the mask view.
697
697
UIGraphicsBeginImageContextWithOptions (self.bounds .size , NO , [UIScreen mainScreen ].scale );
698
698
CGContextRef context = UIGraphicsGetCurrentContext ();
699
+
700
+ if (!context) {
701
+ return ;
702
+ }
703
+
699
704
// Create the gradient
700
705
size_t locationsCount = 2 ;
701
706
CGFloat locations[2 ] = {0 .0f , 1 .0f };
@@ -713,52 +718,53 @@ - (void)drawMask
713
718
UIGraphicsEndImageContext ();
714
719
// Set the background
715
720
maskView.backgroundColor = [UIColor colorWithPatternImage: image];
721
+
716
722
} else if (_maskType == M13ProgressHUDMaskTypeIOS7Blur) {
717
723
// do nothing; we don't want to take a snapshot of the background for blurring now, no idea what the background is
718
724
}
719
725
}
720
726
721
727
- (void )redrawBlurs
722
728
{
723
- if (_maskType == M13ProgressHUDMaskTypeIOS7Blur) {
724
- // Get the snapshot of the mask
725
- __block UIImage *image = [self snapshotForBlurredBackgroundInView: maskView];
726
- if (image != nil ) {
727
- // Apply the filters to blur the image
728
- dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 ), ^{
729
- image = [image applyLightEffect ];
730
- dispatch_async (dispatch_get_main_queue (), ^{
731
- // Fade on content's change, if there was already an image.
732
- CATransition *transition = [CATransition new ];
733
- transition.duration = 0.3 ;
734
- transition.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut ];
735
- transition.type = kCATransitionFade ;
736
- [self ->maskView.layer addAnimation: transition forKey: nil ];
737
- self->maskView .backgroundColor = [UIColor colorWithPatternImage: image];
738
- });
729
+ if (_maskType == M13ProgressHUDMaskTypeIOS7Blur) {
730
+ // Get the snapshot of the mask
731
+ __block UIImage *image = [self snapshotForBlurredBackgroundInView: maskView];
732
+ if (image != nil ) {
733
+ // Apply the filters to blur the image
734
+ dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 ), ^{
735
+ image = [image applyLightEffect ];
736
+ dispatch_async (dispatch_get_main_queue (), ^{
737
+ // Fade on content's change, if there was already an image.
738
+ CATransition *transition = [CATransition new ];
739
+ transition.duration = 0.3 ;
740
+ transition.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut ];
741
+ transition.type = kCATransitionFade ;
742
+ [self ->maskView.layer addAnimation: transition forKey: nil ];
743
+ self->maskView .backgroundColor = [UIColor colorWithPatternImage: image];
739
744
});
740
- }
745
+ });
741
746
}
742
- if (_applyBlurToBackground) {
743
- // Get the snapshot of the mask
744
- __block UIImage *image = [ self snapshotForBlurredBackgroundInView: backgroundView];
745
- if ( image != nil ) {
746
- // Apply the filters to blur the image
747
- dispatch_async ( dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 ), ^{
748
- // image = [image applyLightEffect];
749
- image = [image applyLightEffect ];
750
- dispatch_async ( dispatch_get_main_queue (), ^{
751
- // Fade on content's change, if there was already an image.
752
- CATransition *transition = [ CATransition new ];
753
- transition. duration = 0.3 ;
754
- transition.timingFunction = [ CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut ] ;
755
- transition.type = kCATransitionFade ;
756
- [ self ->backgroundView.layer addAnimation: transition forKey: nil ] ;
757
- self->backgroundView .backgroundColor = [UIColor colorWithPatternImage: image ];
758
- }) ;
747
+ }
748
+ if (_applyBlurToBackground) {
749
+ // Get the snapshot of the mask
750
+ __block UIImage * image = [ self snapshotForBlurredBackgroundInView: backgroundView];
751
+ if (image != nil ) {
752
+ // Apply the filters to blur the image
753
+ dispatch_async ( dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 ), ^{
754
+ // image = [image applyLightEffect];
755
+ image = [image applyLightEffect ];
756
+ dispatch_async ( dispatch_get_main_queue (), ^{
757
+ // Fade on content's change, if there was already an image.
758
+ CATransition * transition = [ CATransition new ] ;
759
+ transition.duration = 0.3 ;
760
+ transition.timingFunction = [ CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut ] ;
761
+ transition. type = kCATransitionFade ;
762
+ [ self ->backgroundView.layer addAnimation: transition forKey: nil ];
763
+ self-> backgroundView . backgroundColor = [UIColor colorWithPatternImage: image] ;
759
764
});
760
- }
765
+ });
761
766
}
767
+ }
762
768
}
763
769
764
770
- (UIImage *)snapshotForBlurredBackgroundInView : (UIView *)view
0 commit comments