Skip to content

Commit fb5f616

Browse files
authored
Merge pull request #39 from pakmee/swift2.3
converted to swift 2.3 and fixed auto correct with context
2 parents edeba04 + aa4edac commit fb5f616

File tree

2 files changed

+35
-23
lines changed

2 files changed

+35
-23
lines changed

KDCircularProgress/KDCircularProgress.swift

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public enum KDCircularProgressGlowMode {
1313
}
1414

1515
@IBDesignable
16-
public class KDCircularProgress: UIView {
16+
public class KDCircularProgress: UIView,CAAnimationDelegate {
1717

1818
private struct Conversion {
1919
static func degreesToRadians (value:CGFloat) -> CGFloat {
@@ -291,7 +291,7 @@ public class KDCircularProgress: UIView {
291291
}
292292

293293
public func pauseAnimation() {
294-
guard let presentationLayer = progressLayer.presentationLayer() as? KDCircularProgressViewLayer else { return }
294+
guard let presentationLayer = progressLayer.presentationLayer() else { return }
295295
let currentValue = presentationLayer.angle
296296
progressLayer.removeAllAnimations()
297297
animationCompletionBlock = nil
@@ -308,10 +308,10 @@ public class KDCircularProgress: UIView {
308308
return progressLayer.animationForKey("angle") != nil
309309
}
310310

311-
override public func animationDidStop(anim: CAAnimation, finished flag: Bool) {
311+
public func animationDidStop(anim: CAAnimation, finished flag: Bool) {
312312
if let completionBlock = animationCompletionBlock {
313313
if flag {
314-
animationCompletionBlock = nil
314+
animationCompletionBlock = nil
315315
}
316316

317317
completionBlock(flag)
@@ -439,28 +439,34 @@ public class KDCircularProgress: UIView {
439439
CGContextDrawPath(ctx, .FillStroke)
440440

441441
UIGraphicsBeginImageContextWithOptions(size, false, 0.0)
442-
443-
let imageCtx = UIGraphicsGetCurrentContext()
444442
let reducedAngle = Utility.mod(angle, range: 360, minMax: (0, 360))
445-
let fromAngle = Conversion.degreesToRadians(CGFloat(-startAngle))
446-
let toAngle = Conversion.degreesToRadians(CGFloat((clockwise == true ? -reducedAngle : reducedAngle) - startAngle))
447-
448-
CGContextAddArc(imageCtx, width/2.0, height/2.0, arcRadius, fromAngle, toAngle, clockwise == true ? 1 : 0)
449443

450-
let glowValue = GlowConstants.glowAmountForAngle(reducedAngle, glowAmount: glowAmount, glowMode: glowMode, size: width)
451-
if glowValue > 0 {
452-
CGContextSetShadowWithColor(imageCtx, CGSizeZero, glowValue, UIColor.blackColor().CGColor)
444+
if let imageCtx = UIGraphicsGetCurrentContext(){
445+
let fromAngle = Conversion.degreesToRadians(CGFloat(-startAngle))
446+
let toAngle = Conversion.degreesToRadians(CGFloat((clockwise == true ? -reducedAngle : reducedAngle) - startAngle))
447+
448+
CGContextAddArc(imageCtx, width/2.0, height/2.0, arcRadius, fromAngle, toAngle, clockwise == true ? 1 : 0)
449+
450+
let glowValue = GlowConstants.glowAmountForAngle(reducedAngle, glowAmount: glowAmount, glowMode: glowMode, size: width)
451+
if glowValue > 0 {
452+
CGContextSetShadowWithColor(imageCtx, CGSizeZero, glowValue, UIColor.blackColor().CGColor)
453+
}
454+
CGContextSetLineCap(imageCtx, roundedCorners == true ? .Round : .Butt)
455+
CGContextSetLineWidth(imageCtx, progressLineWidth)
456+
CGContextDrawPath(imageCtx, .Stroke)
457+
458+
guard let currentGraphicsContext = UIGraphicsGetCurrentContext() else{
459+
return
460+
}
461+
462+
if let drawMask: CGImageRef = CGBitmapContextCreateImage(currentGraphicsContext){
463+
UIGraphicsEndImageContext()
464+
CGContextSaveGState(ctx)
465+
CGContextClipToMask(ctx, bounds, drawMask)
466+
}else{
467+
UIGraphicsEndImageContext()
468+
}
453469
}
454-
CGContextSetLineCap(imageCtx, roundedCorners == true ? .Round : .Butt)
455-
CGContextSetLineWidth(imageCtx, progressLineWidth)
456-
CGContextDrawPath(imageCtx, .Stroke)
457-
458-
let drawMask: CGImageRef = CGBitmapContextCreateImage(UIGraphicsGetCurrentContext())!
459-
UIGraphicsEndImageContext()
460-
461-
CGContextSaveGState(ctx)
462-
CGContextClipToMask(ctx, bounds, drawMask)
463-
464470
//Gradient - Fill
465471
if !lerpColorMode && colorsArray.count > 1 {
466472
let rgbColorsArray: [UIColor] = colorsArray.map { color in // Make sure every color in colors array is in RGB color space

KDCircularProgressExample/KDCircularProgressExample.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,11 @@
174174
TargetAttributes = {
175175
BC9E75851A8CE4A500B1DF3D = {
176176
CreatedOnToolsVersion = 6.1.1;
177+
LastSwiftMigration = 0800;
177178
};
178179
BC9E759A1A8CE4A500B1DF3D = {
179180
CreatedOnToolsVersion = 6.1.1;
181+
LastSwiftMigration = 0800;
180182
TestTargetID = BC9E75851A8CE4A500B1DF3D;
181183
};
182184
};
@@ -353,6 +355,7 @@
353355
INFOPLIST_FILE = KDCircularProgressExample/Info.plist;
354356
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
355357
PRODUCT_NAME = "$(TARGET_NAME)";
358+
SWIFT_VERSION = 2.3;
356359
};
357360
name = Debug;
358361
};
@@ -363,6 +366,7 @@
363366
INFOPLIST_FILE = KDCircularProgressExample/Info.plist;
364367
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
365368
PRODUCT_NAME = "$(TARGET_NAME)";
369+
SWIFT_VERSION = 2.3;
366370
};
367371
name = Release;
368372
};
@@ -381,6 +385,7 @@
381385
INFOPLIST_FILE = KDCircularProgressExampleTests/Info.plist;
382386
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
383387
PRODUCT_NAME = "$(TARGET_NAME)";
388+
SWIFT_VERSION = 2.3;
384389
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/KDCircularProgressExample.app/KDCircularProgressExample";
385390
};
386391
name = Debug;
@@ -396,6 +401,7 @@
396401
INFOPLIST_FILE = KDCircularProgressExampleTests/Info.plist;
397402
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
398403
PRODUCT_NAME = "$(TARGET_NAME)";
404+
SWIFT_VERSION = 2.3;
399405
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/KDCircularProgressExample.app/KDCircularProgressExample";
400406
};
401407
name = Release;

0 commit comments

Comments
 (0)