OCBarrageCell.m 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // OCBarrageCell.m
  3. // TestApp
  4. //
  5. // Created by QMTV on 2017/8/21.
  6. // Copyright © 2017年 LFC. All rights reserved.
  7. //
  8. #import "OCBarrageCell.h"
  9. @implementation OCBarrageCell
  10. - (instancetype)init {
  11. self = [super init];
  12. if (self) {
  13. _trackIndex = -1;
  14. }
  15. return self;
  16. }
  17. - (void)prepareForReuse {
  18. [self.layer removeAnimationForKey:kBarrageAnimation];
  19. _barrageDescriptor = nil;
  20. if (!_idle) {
  21. _idle = YES;
  22. }
  23. _trackIndex = -1;
  24. }
  25. - (void)setBarrageDescriptor:(OCBarrageDescriptor *)barrageDescriptor {
  26. _barrageDescriptor = barrageDescriptor;
  27. }
  28. - (void)clearContents {
  29. self.layer.contents = nil;
  30. }
  31. - (void)convertContentToImage {
  32. }
  33. - (void)sizeToFit {
  34. CGFloat height = 0.0;
  35. CGFloat width = 0.0;
  36. for (CALayer *sublayer in self.layer.sublayers) {
  37. CGFloat maxY = CGRectGetMaxY(sublayer.frame);
  38. if (maxY > height) {
  39. height = maxY;
  40. }
  41. CGFloat maxX = CGRectGetMaxX(sublayer.frame);
  42. if (maxX > width) {
  43. width = maxX;
  44. }
  45. }
  46. if (width == 0 || height == 0) {
  47. CGImageRef content = (__bridge CGImageRef)self.layer.contents;
  48. if (content) {
  49. UIImage *image = [UIImage imageWithCGImage:content];
  50. width = image.size.width/[UIScreen mainScreen].scale;
  51. height = image.size.height/[UIScreen mainScreen].scale;
  52. }
  53. }
  54. self.bounds = CGRectMake(0.0, 0.0, width, height);
  55. }
  56. - (void)removeSubViewsAndSublayers {
  57. NSEnumerator *viewEnumerator = [self.subviews reverseObjectEnumerator];
  58. UIView *subView = nil;
  59. while (subView = [viewEnumerator nextObject]){
  60. [subView removeFromSuperview];
  61. }
  62. NSEnumerator *layerEnumerator = [self.layer.sublayers reverseObjectEnumerator];
  63. CALayer *sublayer = nil;
  64. while (sublayer = [layerEnumerator nextObject]){
  65. [sublayer removeFromSuperlayer];
  66. }
  67. }
  68. - (void)addBorderAttributes {
  69. if (self.barrageDescriptor.borderColor) {
  70. self.layer.borderColor = self.barrageDescriptor.borderColor.CGColor;
  71. }
  72. if (self.barrageDescriptor.borderWidth > 0) {
  73. self.layer.borderWidth = self.barrageDescriptor.borderWidth;
  74. }
  75. if (self.barrageDescriptor.cornerRadius > 0) {
  76. self.layer.cornerRadius = self.barrageDescriptor.cornerRadius;
  77. }
  78. }
  79. - (void)addBarrageAnimationWithDelegate:(id<CAAnimationDelegate>)animationDelegate {
  80. }
  81. - (void)updateSubviewsData {
  82. }
  83. - (void)layoutContentSubviews {
  84. }
  85. - (CAAnimation *)barrageAnimation {
  86. return [self.layer animationForKey:kBarrageAnimation];
  87. }
  88. @end