Skip to content

Commit

Permalink
Merge pull request #39 from pakmee/swift2.3
Browse files Browse the repository at this point in the history
converted to swift 2.3 and fixed auto correct with context
  • Loading branch information
kaandedeoglu authored Sep 6, 2016
2 parents edeba04 + aa4edac commit fb5f616
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 23 deletions.
52 changes: 29 additions & 23 deletions KDCircularProgress/KDCircularProgress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public enum KDCircularProgressGlowMode {
}

@IBDesignable
public class KDCircularProgress: UIView {
public class KDCircularProgress: UIView,CAAnimationDelegate {

private struct Conversion {
static func degreesToRadians (value:CGFloat) -> CGFloat {
Expand Down Expand Up @@ -291,7 +291,7 @@ public class KDCircularProgress: UIView {
}

public func pauseAnimation() {
guard let presentationLayer = progressLayer.presentationLayer() as? KDCircularProgressViewLayer else { return }
guard let presentationLayer = progressLayer.presentationLayer() else { return }
let currentValue = presentationLayer.angle
progressLayer.removeAllAnimations()
animationCompletionBlock = nil
Expand All @@ -308,10 +308,10 @@ public class KDCircularProgress: UIView {
return progressLayer.animationForKey("angle") != nil
}

override public func animationDidStop(anim: CAAnimation, finished flag: Bool) {
public func animationDidStop(anim: CAAnimation, finished flag: Bool) {
if let completionBlock = animationCompletionBlock {
if flag {
animationCompletionBlock = nil
animationCompletionBlock = nil
}

completionBlock(flag)
Expand Down Expand Up @@ -439,28 +439,34 @@ public class KDCircularProgress: UIView {
CGContextDrawPath(ctx, .FillStroke)

UIGraphicsBeginImageContextWithOptions(size, false, 0.0)

let imageCtx = UIGraphicsGetCurrentContext()
let reducedAngle = Utility.mod(angle, range: 360, minMax: (0, 360))
let fromAngle = Conversion.degreesToRadians(CGFloat(-startAngle))
let toAngle = Conversion.degreesToRadians(CGFloat((clockwise == true ? -reducedAngle : reducedAngle) - startAngle))

CGContextAddArc(imageCtx, width/2.0, height/2.0, arcRadius, fromAngle, toAngle, clockwise == true ? 1 : 0)

let glowValue = GlowConstants.glowAmountForAngle(reducedAngle, glowAmount: glowAmount, glowMode: glowMode, size: width)
if glowValue > 0 {
CGContextSetShadowWithColor(imageCtx, CGSizeZero, glowValue, UIColor.blackColor().CGColor)
if let imageCtx = UIGraphicsGetCurrentContext(){
let fromAngle = Conversion.degreesToRadians(CGFloat(-startAngle))
let toAngle = Conversion.degreesToRadians(CGFloat((clockwise == true ? -reducedAngle : reducedAngle) - startAngle))

CGContextAddArc(imageCtx, width/2.0, height/2.0, arcRadius, fromAngle, toAngle, clockwise == true ? 1 : 0)

let glowValue = GlowConstants.glowAmountForAngle(reducedAngle, glowAmount: glowAmount, glowMode: glowMode, size: width)
if glowValue > 0 {
CGContextSetShadowWithColor(imageCtx, CGSizeZero, glowValue, UIColor.blackColor().CGColor)
}
CGContextSetLineCap(imageCtx, roundedCorners == true ? .Round : .Butt)
CGContextSetLineWidth(imageCtx, progressLineWidth)
CGContextDrawPath(imageCtx, .Stroke)

guard let currentGraphicsContext = UIGraphicsGetCurrentContext() else{
return
}

if let drawMask: CGImageRef = CGBitmapContextCreateImage(currentGraphicsContext){
UIGraphicsEndImageContext()
CGContextSaveGState(ctx)
CGContextClipToMask(ctx, bounds, drawMask)
}else{
UIGraphicsEndImageContext()
}
}
CGContextSetLineCap(imageCtx, roundedCorners == true ? .Round : .Butt)
CGContextSetLineWidth(imageCtx, progressLineWidth)
CGContextDrawPath(imageCtx, .Stroke)

let drawMask: CGImageRef = CGBitmapContextCreateImage(UIGraphicsGetCurrentContext())!
UIGraphicsEndImageContext()

CGContextSaveGState(ctx)
CGContextClipToMask(ctx, bounds, drawMask)

//Gradient - Fill
if !lerpColorMode && colorsArray.count > 1 {
let rgbColorsArray: [UIColor] = colorsArray.map { color in // Make sure every color in colors array is in RGB color space
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,11 @@
TargetAttributes = {
BC9E75851A8CE4A500B1DF3D = {
CreatedOnToolsVersion = 6.1.1;
LastSwiftMigration = 0800;
};
BC9E759A1A8CE4A500B1DF3D = {
CreatedOnToolsVersion = 6.1.1;
LastSwiftMigration = 0800;
TestTargetID = BC9E75851A8CE4A500B1DF3D;
};
};
Expand Down Expand Up @@ -353,6 +355,7 @@
INFOPLIST_FILE = KDCircularProgressExample/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 2.3;
};
name = Debug;
};
Expand All @@ -363,6 +366,7 @@
INFOPLIST_FILE = KDCircularProgressExample/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 2.3;
};
name = Release;
};
Expand All @@ -381,6 +385,7 @@
INFOPLIST_FILE = KDCircularProgressExampleTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 2.3;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/KDCircularProgressExample.app/KDCircularProgressExample";
};
name = Debug;
Expand All @@ -396,6 +401,7 @@
INFOPLIST_FILE = KDCircularProgressExampleTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 2.3;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/KDCircularProgressExample.app/KDCircularProgressExample";
};
name = Release;
Expand Down

0 comments on commit fb5f616

Please sign in to comment.