123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- //
- // YOUPAIOCBarrageTextCell.m
- // TestApp
- //
- // Created by QMTV on 2017/8/23.
- // Copyright © 2017年 LFC. All rights reserved.
- //
- #import "YOUPAIOCBarrageTextCell.h"
- @implementation YOUPAIOCBarrageTextCell
- - (instancetype)init {
- self = [super init];
- if (self) {
-
- }
-
- return self;
- }
- - (void)prepareForReuse {
- [super prepareForReuse];
-
- }
- - (void)youpaifupdateSubviewsData {
- if (!_textLabel) {
- [self addSubview:self.textLabel];
- }
- if (self.textDescriptor.textShadowOpened) {
- self.textLabel.layer.shadowColor = self.textDescriptor.shadowColor.CGColor;
- self.textLabel.layer.shadowOffset = self.textDescriptor.shadowOffset;
- self.textLabel.layer.shadowRadius = self.textDescriptor.shadowRadius;
- self.textLabel.layer.shadowOpacity = self.textDescriptor.shadowOpacity;
- }
-
- [self.textLabel setAttributedText:self.textDescriptor.attributedText];
- }
- - (void)youpaiflayoutContentSubviews {
- CGRect textFrame = [self.textDescriptor.attributedText.string boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:[self.textDescriptor.attributedText attributesAtIndex:0 effectiveRange:NULL] context:nil];
- self.textLabel.frame = textFrame;
- }
- - (void)youpaifconvertContentToImage {
- UIImage *contentImage = [self.layer youpaifconvertContentToImageWithSize:_textLabel.frame.size];
- [self.layer setContents:(__bridge id)contentImage.CGImage];
- }
- - (void)removeSubViewsAndSublayers {
- [super removeSubViewsAndSublayers];
-
- _textLabel = nil;
- }
- - (void)youpaifaddBarrageAnimationWithDelegate:(id<CAAnimationDelegate>)animationDelegate {
- if (!self.superview) {
- return;
- }
-
- CGPoint startCenter = CGPointMake(CGRectGetMaxX(self.superview.bounds) + CGRectGetWidth(self.bounds)/2, self.center.y);
- CGPoint endCenter = CGPointMake(-(CGRectGetWidth(self.bounds)/2), self.center.y);
-
- CGFloat animationDuration = self.barrageDescriptor.animationDuration;
- if (self.barrageDescriptor.fixedSpeed > 0.0) {//如果是固定速度那就用固定速度
- if (self.barrageDescriptor.fixedSpeed > 100.0) {
- self.barrageDescriptor.fixedSpeed = 100.0;
- }
- animationDuration = (startCenter.x - endCenter.x)/([UIScreen mainScreen].scale*2)/self.barrageDescriptor.fixedSpeed;
- }
-
- CAKeyframeAnimation *walkAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
- walkAnimation.values = @[[NSValue valueWithCGPoint:startCenter], [NSValue valueWithCGPoint:endCenter]];
- walkAnimation.keyTimes = @[@(0.0), @(1.0)];
- walkAnimation.duration = animationDuration;
- walkAnimation.repeatCount = 1;
- walkAnimation.delegate = animationDelegate;
- walkAnimation.removedOnCompletion = NO;
- walkAnimation.fillMode = kCAFillModeForwards;
-
- [self.layer addAnimation:walkAnimation forKey:kBarrageAnimation];
- }
- - (UILabel *)textLabel {
- if (!_textLabel) {
- _textLabel = [[UILabel alloc] init];
- _textLabel.textAlignment = NSTextAlignmentCenter;
- }
-
- return _textLabel;
- }
- - (void)setBarrageDescriptor:(YOUPAIOCBarrageDescriptor *)barrageDescriptor {
- [super setBarrageDescriptor:barrageDescriptor];
- self.textDescriptor = (YOUPAIOCBarrageTextDescriptor *)barrageDescriptor;
- }
- @end
|