YOUPAIOCBarrageBecomeNobleCell.m 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // YOUPAIOCBarrageBecomeNobleCell.m
  3. // QuanMinTV
  4. //
  5. // Created by QMTV on 2017/8/31.
  6. // Copyright © 2017年 QMTV. All rights reserved.
  7. //
  8. #import "YOUPAIOCBarrageBecomeNobleCell.h"
  9. @implementation YOUPAIOCBarrageBecomeNobleCell
  10. - (instancetype)init {
  11. self = [super init];
  12. if (self) {
  13. [self addsublayers];
  14. }
  15. return self;
  16. }
  17. - (void)addsublayers {
  18. [self.layer insertSublayer:self.backgroundImageLayer atIndex:0];
  19. }
  20. - (void)prepareForReuse {
  21. [super prepareForReuse];
  22. [self addsublayers];
  23. }
  24. - (void)youpaifupdateSubviewsData {
  25. [super youpaifupdateSubviewsData];
  26. [self.backgroundImageLayer setContents:(__bridge id)self.nobleDescriptor.backgroundImage.CGImage];
  27. }
  28. - (void)youpaiflayoutContentSubviews {
  29. [super youpaiflayoutContentSubviews];
  30. self.backgroundImageLayer.frame = CGRectMake(0.0, 0.0, self.nobleDescriptor.backgroundImage.size.width, self.nobleDescriptor.backgroundImage.size.height);
  31. CGPoint center = self.backgroundImageLayer.position;
  32. center.y += 17.0;
  33. self.textLabel.center = center;
  34. }
  35. - (void)youpaifconvertContentToImage {
  36. UIImage *image = [self.layer youpaifconvertContentToImageWithSize:CGSizeMake(self.nobleDescriptor.backgroundImage.size.width, self.nobleDescriptor.backgroundImage.size.height)];
  37. [self.layer setContents:(__bridge id)image.CGImage];
  38. }
  39. - (void)youpaifaddBarrageAnimationWithDelegate:(id<CAAnimationDelegate>)animationDelegate {
  40. if (!self.superview) {
  41. return;
  42. }
  43. CGPoint startCenter = CGPointMake(CGRectGetMaxX(self.superview.bounds) + CGRectGetWidth(self.bounds)/2, self.center.y);
  44. CGPoint stopCenter = CGPointMake(CGRectGetMidX(self.superview.bounds), self.center.y);
  45. CGPoint endCenter = CGPointMake(-(CGRectGetWidth(self.bounds)/2), self.center.y);
  46. CAKeyframeAnimation *walkAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
  47. walkAnimation.values = @[[NSValue valueWithCGPoint:startCenter], [NSValue valueWithCGPoint:stopCenter], [NSValue valueWithCGPoint:stopCenter], [NSValue valueWithCGPoint:endCenter]];
  48. walkAnimation.keyTimes = @[@(0.0), @(0.25), @(0.75), @(1.0)];
  49. walkAnimation.duration = self.barrageDescriptor.animationDuration;
  50. walkAnimation.repeatCount = 1;
  51. walkAnimation.delegate = animationDelegate;
  52. walkAnimation.removedOnCompletion = NO;
  53. walkAnimation.fillMode = kCAFillModeForwards;
  54. [self.layer addAnimation:walkAnimation forKey:kBarrageAnimation];
  55. }
  56. #pragma mark ---- setter
  57. - (void)setBarrageDescriptor:(YOUPAIOCBarrageDescriptor *)barrageDescriptor {
  58. [super setBarrageDescriptor:barrageDescriptor];
  59. self.nobleDescriptor = (YOUPAIOCBarrageBecomeNobleDescriptor *)barrageDescriptor;
  60. }
  61. #pragma mark ---- getter
  62. - (CALayer *)backgroundImageLayer {
  63. if (!_backgroundImageLayer) {
  64. _backgroundImageLayer = [[CALayer alloc] init];
  65. }
  66. return _backgroundImageLayer;
  67. }
  68. @end