Skip to content

Commit

Permalink
Fixed invalid context error: Issue Marxon13#35
Browse files Browse the repository at this point in the history
  • Loading branch information
Marxon13 committed Aug 10, 2016
1 parent 31fec48 commit c89079d
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 50 deletions.
88 changes: 47 additions & 41 deletions Classes/HUD/M13ProgressHUD.m
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ - (void)show:(BOOL)animated
[self setNeedsDisplay];

onScreen = YES;

//Animate the HUD on screen
CABasicAnimation *fadeAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
fadeAnimation.duration = _animationDuration;
Expand Down Expand Up @@ -329,7 +329,7 @@ - (void)show:(BOOL)animated
{
positionAnimation.fromValue = [NSValue valueWithCGPoint:_animationPoint];
}

positionAnimation.toValue = [NSValue valueWithCGPoint:backgroundView.layer.position];
positionAnimation.removedOnCompletion = YES;

Expand All @@ -350,15 +350,15 @@ - (void)hide:(BOOL)animated
fadeAnimation.fromValue = [NSNumber numberWithFloat:1.0];
fadeAnimation.toValue = [NSNumber numberWithFloat:0.0];
fadeAnimation.removedOnCompletion = YES;

[self.layer addAnimation:fadeAnimation forKey:@"fadeAnimation"];
self.layer.opacity = 0.0;

CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
scaleAnimation.fromValue = [NSNumber numberWithFloat:1.0];
scaleAnimation.toValue = [NSNumber numberWithFloat:0.0];
scaleAnimation.removedOnCompletion = YES;

CABasicAnimation *frameAnimation = [CABasicAnimation animationWithKeyPath:@"position"];

if (_animationCentered)
Expand Down Expand Up @@ -407,7 +407,7 @@ - (void)unregisterFromNotificationCenter {

- (void)deviceOrientationDidChange:(NSNotification *)notification {
UIDeviceOrientation deviceOrientation = [notification.object orientation];

if (_shouldAutorotate && UIDeviceOrientationIsValidInterfaceOrientation(deviceOrientation)) {
if (UIDeviceOrientationIsPortrait(deviceOrientation)) {
if (deviceOrientation == UIDeviceOrientationPortraitUpsideDown) {
Expand Down Expand Up @@ -556,7 +556,7 @@ - (void)layoutHUD
}

backgroundRect.origin.x = (self.bounds.size.width / 2.0) - (backgroundRect.size.width / 2.0);
backgroundRect.origin.y = (self.bounds.size.height / 2.0) - (_minimumSize.height / 2.0);
backgroundRect.origin.y = (self.bounds.size.height / 2.0) - (_minimumSize.height / 2.0);

//There is no status label text, center the progress view
progressRect.origin.x = (backgroundRect.size.width / 2.0) - (progressRect.size.width / 2.0);
Expand Down Expand Up @@ -696,6 +696,11 @@ - (void)drawMask
//Create the gradient as an image, and then set it as the color of the mask view.
UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, [UIScreen mainScreen].scale);
CGContextRef context = UIGraphicsGetCurrentContext();

if (!context) {
return;
}

//Create the gradient
size_t locationsCount = 2;
CGFloat locations[2] = {0.0f, 1.0f};
Expand All @@ -713,52 +718,53 @@ - (void)drawMask
UIGraphicsEndImageContext();
//Set the background
maskView.backgroundColor = [UIColor colorWithPatternImage:image];

} else if (_maskType == M13ProgressHUDMaskTypeIOS7Blur) {
// do nothing; we don't want to take a snapshot of the background for blurring now, no idea what the background is
}
}

- (void)redrawBlurs
{
if (_maskType == M13ProgressHUDMaskTypeIOS7Blur) {
//Get the snapshot of the mask
__block UIImage *image = [self snapshotForBlurredBackgroundInView:maskView];
if (image != nil) {
//Apply the filters to blur the image
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
image = [image applyLightEffect];
dispatch_async(dispatch_get_main_queue(), ^{
// Fade on content's change, if there was already an image.
CATransition *transition = [CATransition new];
transition.duration = 0.3;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;
[self->maskView.layer addAnimation:transition forKey:nil];
self->maskView.backgroundColor = [UIColor colorWithPatternImage:image];
});
if (_maskType == M13ProgressHUDMaskTypeIOS7Blur) {
//Get the snapshot of the mask
__block UIImage *image = [self snapshotForBlurredBackgroundInView:maskView];
if (image != nil) {
//Apply the filters to blur the image
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
image = [image applyLightEffect];
dispatch_async(dispatch_get_main_queue(), ^{
// Fade on content's change, if there was already an image.
CATransition *transition = [CATransition new];
transition.duration = 0.3;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;
[self->maskView.layer addAnimation:transition forKey:nil];
self->maskView.backgroundColor = [UIColor colorWithPatternImage:image];
});
}
});
}
if (_applyBlurToBackground) {
//Get the snapshot of the mask
__block UIImage *image = [self snapshotForBlurredBackgroundInView:backgroundView];
if (image != nil) {
//Apply the filters to blur the image
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//image = [image applyLightEffect];
image = [image applyLightEffect];
dispatch_async(dispatch_get_main_queue(), ^{
// Fade on content's change, if there was already an image.
CATransition *transition = [CATransition new];
transition.duration = 0.3;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;
[self->backgroundView.layer addAnimation:transition forKey:nil];
self->backgroundView.backgroundColor = [UIColor colorWithPatternImage:image];
});
}
if (_applyBlurToBackground) {
//Get the snapshot of the mask
__block UIImage *image = [self snapshotForBlurredBackgroundInView:backgroundView];
if (image != nil) {
//Apply the filters to blur the image
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//image = [image applyLightEffect];
image = [image applyLightEffect];
dispatch_async(dispatch_get_main_queue(), ^{
// Fade on content's change, if there was already an image.
CATransition *transition = [CATransition new];
transition.duration = 0.3;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;
[self->backgroundView.layer addAnimation:transition forKey:nil];
self->backgroundView.backgroundColor = [UIColor colorWithPatternImage:image];
});
}
});
}
}
}

- (UIImage *)snapshotForBlurredBackgroundInView:(UIView *)view
Expand Down
18 changes: 9 additions & 9 deletions M13ProgressSuite.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
62BB86001C87300F0019306A /* UIApplication+M13ProgressSuite.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "UIApplication+M13ProgressSuite.m"; path = "Classes/Application/UIApplication+M13ProgressSuite.m"; sourceTree = "<group>"; };
CA1C945C18CCF59500B469BF /* M13ProgressViewMetroDotPolygon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = M13ProgressViewMetroDotPolygon.h; path = Classes/ProgressViews/M13ProgressViewMetroDotPolygon.h; sourceTree = "<group>"; };
CA1C945D18CCF59500B469BF /* M13ProgressViewMetroDotPolygon.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = M13ProgressViewMetroDotPolygon.m; path = Classes/ProgressViews/M13ProgressViewMetroDotPolygon.m; sourceTree = "<group>"; };
CA2FAF981889907300BCAEF5 /* M13ProgressSuite.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = M13ProgressSuite.app; sourceTree = BUILT_PRODUCTS_DIR; };
CA2FAF981889907300BCAEF5 /* M13ProgressSuiteDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = M13ProgressSuiteDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
CA2FAF9B1889907300BCAEF5 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
CA2FAF9D1889907300BCAEF5 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
CA2FAF9F1889907300BCAEF5 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -288,7 +288,7 @@
CA2FAF991889907300BCAEF5 /* Products */ = {
isa = PBXGroup;
children = (
CA2FAF981889907300BCAEF5 /* M13ProgressSuite.app */,
CA2FAF981889907300BCAEF5 /* M13ProgressSuiteDemo.app */,
CA2FAFBC1889907300BCAEF5 /* M13ProgressSuiteTests.xctest */,
FB2A7BDC1B793E5600FE4E4A /* M13ProgressSuite.framework */,
);
Expand Down Expand Up @@ -629,9 +629,9 @@
/* End PBXHeadersBuildPhase section */

/* Begin PBXNativeTarget section */
CA2FAF971889907300BCAEF5 /* M13ProgressSuite */ = {
CA2FAF971889907300BCAEF5 /* M13ProgressSuiteDemo */ = {
isa = PBXNativeTarget;
buildConfigurationList = CA2FAFCD1889907300BCAEF5 /* Build configuration list for PBXNativeTarget "M13ProgressSuite" */;
buildConfigurationList = CA2FAFCD1889907300BCAEF5 /* Build configuration list for PBXNativeTarget "M13ProgressSuiteDemo" */;
buildPhases = (
CA2FAF941889907300BCAEF5 /* Sources */,
CA2FAF951889907300BCAEF5 /* Frameworks */,
Expand All @@ -643,9 +643,9 @@
dependencies = (
FB2A7BF21B793E5600FE4E4A /* PBXTargetDependency */,
);
name = M13ProgressSuite;
name = M13ProgressSuiteDemo;
productName = M13ProgressSuite;
productReference = CA2FAF981889907300BCAEF5 /* M13ProgressSuite.app */;
productReference = CA2FAF981889907300BCAEF5 /* M13ProgressSuiteDemo.app */;
productType = "com.apple.product-type.application";
};
CA2FAFBB1889907300BCAEF5 /* M13ProgressSuiteTests */ = {
Expand Down Expand Up @@ -714,7 +714,7 @@
projectDirPath = "";
projectRoot = "";
targets = (
CA2FAF971889907300BCAEF5 /* M13ProgressSuite */,
CA2FAF971889907300BCAEF5 /* M13ProgressSuiteDemo */,
CA2FAFBB1889907300BCAEF5 /* M13ProgressSuiteTests */,
FB2A7BDB1B793E5600FE4E4A /* M13ProgressSuiteFramework */,
CA2FB0431889986D00BCAEF5 /* Documentation */,
Expand Down Expand Up @@ -834,7 +834,7 @@
/* Begin PBXTargetDependency section */
CA2FAFC21889907300BCAEF5 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = CA2FAF971889907300BCAEF5 /* M13ProgressSuite */;
target = CA2FAF971889907300BCAEF5 /* M13ProgressSuiteDemo */;
targetProxy = CA2FAFC11889907300BCAEF5 /* PBXContainerItemProxy */;
};
FB2A7BF21B793E5600FE4E4A /* PBXTargetDependency */ = {
Expand Down Expand Up @@ -1112,7 +1112,7 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
CA2FAFCD1889907300BCAEF5 /* Build configuration list for PBXNativeTarget "M13ProgressSuite" */ = {
CA2FAFCD1889907300BCAEF5 /* Build configuration list for PBXNativeTarget "M13ProgressSuiteDemo" */ = {
isa = XCConfigurationList;
buildConfigurations = (
CA2FAFCE1889907300BCAEF5 /* Debug */,
Expand Down
35 changes: 35 additions & 0 deletions M13ProgressSuite/Images.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
},
{
"size" : "40x40",
"idiom" : "iphone",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
},
{
"size" : "60x60",
"idiom" : "iphone",
Expand All @@ -24,6 +44,16 @@
"filename" : "[email protected]",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"size" : "29x29",
"idiom" : "ipad",
Expand Down Expand Up @@ -59,6 +89,11 @@
"idiom" : "ipad",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
}
],
"info" : {
Expand Down

0 comments on commit c89079d

Please sign in to comment.