react-native-navigation的迁移库

BaseAnimator.m 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #import "BaseAnimator.h"
  2. @implementation BaseAnimator {
  3. NSMutableArray* _mutableAnimations;
  4. }
  5. - (void)setAnimations:(NSArray<id<DisplayLinkAnimation>> *)animations {
  6. _animations = animations;
  7. _mutableAnimations = [NSMutableArray arrayWithArray:animations];
  8. }
  9. - (void)updateAnimations:(NSTimeInterval)elapsed {
  10. CATransform3D transform = CATransform3DIdentity;
  11. for (int i = 0; i < _mutableAnimations.count; i++) {
  12. id<DisplayLinkAnimation> animation = _mutableAnimations[i];
  13. if (elapsed < animation.duration + animation.startDelay && elapsed > animation.startDelay) {
  14. CGFloat p = (elapsed-animation.startDelay)/(animation.duration-animation.startDelay);
  15. transform = CATransform3DConcat(transform, [animation animateWithProgress:p]);
  16. } else if (elapsed >= animation.duration + animation.startDelay) {
  17. transform = CATransform3DConcat(transform, [animation animateWithProgress:1]);
  18. [animation end];
  19. [_mutableAnimations removeObject:animation];
  20. }
  21. }
  22. self.view.layer.transform = transform;
  23. }
  24. - (NSTimeInterval)maxDuration {
  25. CGFloat maxDuration = 0;
  26. for (id<DisplayLinkAnimation> animation in _animations) {
  27. if (animation.duration + animation.startDelay > maxDuration) {
  28. maxDuration = animation.duration;
  29. }
  30. }
  31. return maxDuration;
  32. }
  33. - (void)end {
  34. for (id<DisplayLinkAnimatorDelegate> animation in _animations) {
  35. if ([animation respondsToSelector:@selector(end)]) {
  36. [animation end];
  37. }
  38. }
  39. }
  40. @end