Skip to content

Commit

Permalink
Add relativeDuration default value to animate methods to specify if t…
Browse files Browse the repository at this point in the history
…he duration is global or specific to current angle
  • Loading branch information
kaandedeoglu committed Nov 11, 2015
1 parent 54e24f1 commit f9194ec
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions KDCircularProgress/KDCircularProgress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -228,27 +228,36 @@ public class KDCircularProgress: UIView {
progressLayer.setNeedsDisplay()
}

public func animateFromAngle(fromAngle: Int, toAngle: Int, duration: NSTimeInterval, completion: ((Bool) -> Void)?) {
public func animateFromAngle(fromAngle: Int, toAngle: Int, duration: NSTimeInterval, relativeDuration: Bool = true, completion: ((Bool) -> Void)?) {
if isAnimating() {
pauseAnimation()
}

let animationDuration: NSTimeInterval
if relativeDuration {
animationDuration = duration
} else {
let traveledAngle = UtilityFunctions.Mod(toAngle - fromAngle, range: 360, minMax: (0, 360))
let scaledDuration = (NSTimeInterval(traveledAngle) * duration) / 360
animationDuration = scaledDuration
}

let animation = CABasicAnimation(keyPath: "angle")
animation.fromValue = fromAngle
animation.toValue = toAngle
animation.duration = duration
animation.duration = animationDuration
animation.delegate = self
angle = toAngle
animationCompletionBlock = completion

progressLayer.addAnimation(animation, forKey: "angle")
}

public func animateToAngle(toAngle: Int, duration: NSTimeInterval, completion: ((Bool) -> Void)?) {
public func animateToAngle(toAngle: Int, duration: NSTimeInterval, relativeDuration: Bool = true, completion: ((Bool) -> Void)?) {
if isAnimating() {
pauseAnimation()
}
animateFromAngle(angle, toAngle: toAngle, duration: duration, completion: completion)
animateFromAngle(angle, toAngle: toAngle, duration: duration, relativeDuration: relativeDuration, completion: completion)
}

public func pauseAnimation() {
Expand Down

0 comments on commit f9194ec

Please sign in to comment.