YOUPAIOCBarrageGifCell.m 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // YOUPAIOCBarrageGifCell.m
  3. // OCBarrage
  4. //
  5. // Created by QMTV on 2017/8/31.
  6. // Copyright © 2017年 LFC. All rights reserved.
  7. //
  8. #import "YOUPAIOCBarrageGifCell.h"
  9. @implementation YOUPAIOCBarrageGifCell
  10. - (instancetype)init {
  11. self = [super init];
  12. if (self) {
  13. [self addSubviews];
  14. }
  15. return self;
  16. }
  17. - (void)addSubviews {
  18. [self addSubview:self.imageView];
  19. }
  20. - (void)youpaifupdateSubviewsData {
  21. self.imageView.image = self.gifDescriptor.image;
  22. }
  23. - (void)youpaiflayoutContentSubviews {
  24. self.imageView.frame = CGRectMake(0.0, 0.0, 100.0, 100.0);
  25. }
  26. - (void)youpaifaddBarrageAnimationWithDelegate:(id<CAAnimationDelegate>)animationDelegate {
  27. if (!self.superview) {
  28. return;
  29. }
  30. CGPoint startCenter = CGPointMake(CGRectGetMaxX(self.superview.bounds) + CGRectGetWidth(self.bounds)/2, self.center.y);
  31. CGPoint endCenter = CGPointMake(-(CGRectGetWidth(self.bounds)/2), self.center.y);
  32. CAKeyframeAnimation *walkAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
  33. walkAnimation.values = @[[NSValue valueWithCGPoint:startCenter], [NSValue valueWithCGPoint:endCenter]];
  34. walkAnimation.keyTimes = @[@(0.0), @(1.0)];
  35. walkAnimation.duration = self.barrageDescriptor.animationDuration;
  36. walkAnimation.repeatCount = 1;
  37. walkAnimation.delegate = animationDelegate;
  38. walkAnimation.removedOnCompletion = NO;
  39. walkAnimation.fillMode = kCAFillModeForwards;
  40. [self.layer addAnimation:walkAnimation forKey:kBarrageAnimation];
  41. }
  42. - (void)removeSubViewsAndSublayers {
  43. }
  44. #pragma mark ---- setter
  45. - (void)setBarrageDescriptor:(YOUPAIOCBarrageDescriptor *)barrageDescriptor {
  46. [super setBarrageDescriptor:barrageDescriptor];
  47. self.gifDescriptor = (YOUPAIOCBarrageGifDescriptor *)barrageDescriptor;
  48. }
  49. #pragma mark ---- getter
  50. - (YYAnimatedImageView *)imageView {
  51. if (!_imageView) {
  52. _imageView = [[YYAnimatedImageView alloc] init];
  53. _imageView.autoPlayAnimatedImage = YES;
  54. }
  55. return _imageView;
  56. }
  57. @end