POPCustomAnimation.mm 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. Copyright (c) 2014-present, Facebook, Inc.
  3. All rights reserved.
  4. This source code is licensed under the BSD-style license found in the
  5. LICENSE file in the root directory of this source tree. An additional grant
  6. of patent rights can be found in the PATENTS file in the same directory.
  7. */
  8. #import "POPAnimationInternal.h"
  9. #import "POPCustomAnimation.h"
  10. @interface POPCustomAnimation ()
  11. @property (nonatomic, copy) POPCustomAnimationBlock animate;
  12. @end
  13. @implementation POPCustomAnimation
  14. @synthesize currentTime = _currentTime;
  15. @synthesize elapsedTime = _elapsedTime;
  16. @synthesize animate = _animate;
  17. + (instancetype)animationWithBlock:(BOOL(^)(id target, POPCustomAnimation *))block
  18. {
  19. POPCustomAnimation *b = [[self alloc] _init];
  20. b.animate = block;
  21. return b;
  22. }
  23. - (id)_init
  24. {
  25. self = [super _init];
  26. if (nil != self) {
  27. _state->type = kPOPAnimationCustom;
  28. }
  29. return self;
  30. }
  31. - (CFTimeInterval)beginTime
  32. {
  33. POPAnimationState *s = POPAnimationGetState(self);
  34. return s->startTime > 0 ? s->startTime : s->beginTime;
  35. }
  36. - (BOOL)_advance:(id)object currentTime:(CFTimeInterval)currentTime elapsedTime:(CFTimeInterval)elapsedTime
  37. {
  38. _currentTime = currentTime;
  39. _elapsedTime = elapsedTime;
  40. return _animate(object, self);
  41. }
  42. - (void)_appendDescription:(NSMutableString *)s debug:(BOOL)debug
  43. {
  44. [s appendFormat:@"; elapsedTime = %f; currentTime = %f;", _elapsedTime, _currentTime];
  45. }
  46. @end
  47. /**
  48. * Note that only the animate block is copied, but not the current/elapsed times
  49. */
  50. @implementation POPCustomAnimation (NSCopying)
  51. - (instancetype)copyWithZone:(NSZone *)zone {
  52. POPCustomAnimation *copy = [super copyWithZone:zone];
  53. if (copy) {
  54. copy.animate = self.animate;
  55. }
  56. return copy;
  57. }
  58. @end