@@ -228,27 +228,36 @@ public class KDCircularProgress: UIView {
228228 progressLayer. setNeedsDisplay ( )
229229 }
230230
231- public func animateFromAngle( fromAngle: Int , toAngle: Int , duration: NSTimeInterval , completion: ( ( Bool ) -> Void ) ? ) {
231+ public func animateFromAngle( fromAngle: Int , toAngle: Int , duration: NSTimeInterval , relativeDuration : Bool = true , completion: ( ( Bool ) -> Void ) ? ) {
232232 if isAnimating ( ) {
233233 pauseAnimation ( )
234234 }
235+
236+ let animationDuration : NSTimeInterval
237+ if relativeDuration {
238+ animationDuration = duration
239+ } else {
240+ let traveledAngle = UtilityFunctions . Mod ( toAngle - fromAngle, range: 360 , minMax: ( 0 , 360 ) )
241+ let scaledDuration = ( NSTimeInterval ( traveledAngle) * duration) / 360
242+ animationDuration = scaledDuration
243+ }
235244
236245 let animation = CABasicAnimation ( keyPath: " angle " )
237246 animation. fromValue = fromAngle
238247 animation. toValue = toAngle
239- animation. duration = duration
248+ animation. duration = animationDuration
240249 animation. delegate = self
241250 angle = toAngle
242251 animationCompletionBlock = completion
243252
244253 progressLayer. addAnimation ( animation, forKey: " angle " )
245254 }
246255
247- public func animateToAngle( toAngle: Int , duration: NSTimeInterval , completion: ( ( Bool ) -> Void ) ? ) {
256+ public func animateToAngle( toAngle: Int , duration: NSTimeInterval , relativeDuration : Bool = true , completion: ( ( Bool ) -> Void ) ? ) {
248257 if isAnimating ( ) {
249258 pauseAnimation ( )
250259 }
251- animateFromAngle ( angle, toAngle: toAngle, duration: duration, completion: completion)
260+ animateFromAngle ( angle, toAngle: toAngle, duration: duration, relativeDuration : relativeDuration , completion: completion)
252261 }
253262
254263 public func pauseAnimation( ) {
0 commit comments