YOUPAIOCBarrageVerticalAnimationCell.m 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. //
  2. // YOUPAIOCBarrageVerticalAnimationCell.m
  3. // OCBarrage
  4. //
  5. // Created by QMTV on 2018/1/5.
  6. // Copyright © 2018年 LFC. All rights reserved.
  7. //
  8. #import "YOUPAIOCBarrageVerticalAnimationCell.h"
  9. @implementation YOUPAIOCBarrageVerticalAnimationCell
  10. - (void)youpaifaddBarrageAnimationWithDelegate:(id<CAAnimationDelegate>)animationDelegate {
  11. if (!self.superview) {
  12. return;
  13. }
  14. CGPoint startCenter = CGPointMake(CGRectGetMidX(self.superview.bounds), -(CGRectGetHeight(self.bounds)/2));
  15. CGPoint endCenter = CGPointMake(CGRectGetMidX(self.superview.bounds), CGRectGetHeight(self.superview.bounds) + CGRectGetHeight(self.bounds)/2);
  16. CAKeyframeAnimation *walkAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
  17. walkAnimation.values = @[[NSValue valueWithCGPoint:startCenter], [NSValue valueWithCGPoint:endCenter]];
  18. walkAnimation.keyTimes = @[@(0.0), @(1.0)];
  19. walkAnimation.duration = self.barrageDescriptor.animationDuration;
  20. walkAnimation.repeatCount = 1;
  21. walkAnimation.delegate = animationDelegate;
  22. walkAnimation.removedOnCompletion = NO;
  23. walkAnimation.fillMode = kCAFillModeForwards;
  24. [self.layer addAnimation:walkAnimation forKey:kBarrageAnimation];
  25. }
  26. #pragma mark ---- setter
  27. - (void)setBarrageDescriptor:(YOUPAIOCBarrageDescriptor *)barrageDescriptor {
  28. [super setBarrageDescriptor:barrageDescriptor];
  29. self.verticalTextDescriptor = (YOUPAIOCBarrageVerticalTextDescriptor *)barrageDescriptor;
  30. }
  31. @end