LOTNumberInterpolator.m 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //
  2. // LOTNumberInterpolator.m
  3. // Lottie
  4. //
  5. // Created by brandon_withrow on 7/11/17.
  6. // Copyright © 2017 Airbnb. All rights reserved.
  7. //
  8. #import "LOTNumberInterpolator.h"
  9. #import "CGGeometry+LOTAdditions.h"
  10. @implementation LOTNumberInterpolator
  11. - (CGFloat)floatValueForFrame:(NSNumber *)frame {
  12. CGFloat progress = [self progressForFrame:frame];
  13. CGFloat returnValue;
  14. if (progress == 0) {
  15. returnValue = self.leadingKeyframe.floatValue;
  16. } else if (progress == 1) {
  17. returnValue = self.trailingKeyframe.floatValue;
  18. } else {
  19. returnValue = LOT_RemapValue(progress, 0, 1, self.leadingKeyframe.floatValue, self.trailingKeyframe.floatValue);
  20. }
  21. if (self.hasDelegateOverride) {
  22. return [self.delegate floatValueForFrame:frame.floatValue
  23. startKeyframe:self.leadingKeyframe.keyframeTime.floatValue
  24. endKeyframe:self.trailingKeyframe.keyframeTime.floatValue
  25. interpolatedProgress:progress
  26. startValue:self.leadingKeyframe.floatValue
  27. endValue:self.trailingKeyframe.floatValue
  28. currentValue:returnValue];
  29. }
  30. return returnValue;
  31. }
  32. - (BOOL)hasDelegateOverride {
  33. return self.delegate != nil;
  34. }
  35. - (void)setValueDelegate:(id<LOTValueDelegate> _Nonnull)delegate {
  36. NSAssert(([delegate conformsToProtocol:@protocol(LOTNumberValueDelegate)]), @"Number Interpolator set with incorrect callback type. Expected LOTNumberValueDelegate");
  37. self.delegate = (id<LOTNumberValueDelegate>)delegate;
  38. }
  39. @end