diff --git a/Example/RazzleDazzleTests/RAZFilmstripSpec.swift b/Example/RazzleDazzleTests/RAZFilmstripSpec.swift index c2ea581..e6d8a52 100644 --- a/Example/RazzleDazzleTests/RAZFilmstripSpec.swift +++ b/Example/RazzleDazzleTests/RAZFilmstripSpec.swift @@ -105,6 +105,14 @@ class FilmstripSpec: QuickSpec { floatFilmstrip.setValue(30, atTime: 3) expect(floatFilmstrip.valueAtTime(2.5)).to(equal(25)) } + it("should allow replacement of keyframes") { + floatFilmstrip[2] = 0 + floatFilmstrip[4] = 5 + floatFilmstrip[2] = 3 + expect(floatFilmstrip[1]).to(equal(3)) + expect(floatFilmstrip[2]).to(equal(3)) + expect(floatFilmstrip[3]).to(equal(4)) + } } } } diff --git a/Source/Filmstrip.swift b/Source/Filmstrip.swift index cd55bbb..b506f0d 100644 --- a/Source/Filmstrip.swift +++ b/Source/Filmstrip.swift @@ -13,10 +13,6 @@ private class Keyframe { let value : T let easing : EasingFunction - private convenience init(time: CGFloat, value: T) { - self.init(time: time, value: value, easing: EasingFunctionLinear) - } - private init(time: CGFloat, value: T, easing: EasingFunction) { self.time = time self.value = value @@ -48,14 +44,14 @@ public class Filmstrip { } } - public func setValue(value: T, atTime time: CGFloat) { + public func setValue(value: T, atTime time: CGFloat, easing: EasingFunction = EasingFunctionLinear) { let index = indexOfKeyframeAfterTime(time) ?? keyframes.count - keyframes.insert(Keyframe(time: time, value: value), atIndex: index) - } - - public func setValue(value: T, atTime time: CGFloat, easing: EasingFunction) { - let index = indexOfKeyframeAfterTime(time) ?? keyframes.count - keyframes.insert(Keyframe(time: time, value: value, easing: easing), atIndex: index) + if index > 0 && keyframes[index-1].time == time { + keyframes.replaceRange(index-1.. T {