RKLampView.m 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // RKLampView.m
  3. // YBVideo
  4. //
  5. // Created by YunBao on 2018/8/6.
  6. // Copyright © 2018年 cat. All rights reserved.
  7. //
  8. #import "RKLampView.h"
  9. #import <QuartzCore/QuartzCore.h>
  10. @interface RKLampView()
  11. @property(nonatomic,strong)UILabel *label;
  12. @property(nonatomic,strong)UILabel *label2;
  13. @property(nonatomic,strong) UIView *bgView;
  14. @end
  15. @implementation RKLampView
  16. - (instancetype)initWithFrame:(CGRect)frame
  17. {
  18. self = [super initWithFrame:frame];
  19. if (self) {
  20. [self setUI];
  21. }
  22. return self;
  23. }
  24. -(void)setUI {
  25. // 背景视图
  26. _bgView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.frame.size.width, self.frame.size.height)];
  27. [self addSubview:_bgView];
  28. _bgView.backgroundColor = [UIColor clearColor];
  29. _bgView.clipsToBounds = YES;
  30. // 标签视图1
  31. _label = [[UILabel alloc] init];
  32. [_bgView addSubview:_label];
  33. _label.frame = CGRectMake(0.0, 0.0, self.frame.size.width+20, self.frame.size.height);
  34. _label.textColor = [UIColor whiteColor];
  35. _label.font = SYS_Font(15);
  36. // 标签视图2
  37. _label2 = [[UILabel alloc] init];
  38. [_bgView addSubview:_label2];
  39. _label2.frame = CGRectMake(_label.frame.size.width+20, 0.0, self.frame.size.width+20, self.frame.size.height);
  40. _label2.textColor = _label.textColor;
  41. _label2.font = _label.font;
  42. }
  43. -(void)startLamp {
  44. [self removeAllSubViews];
  45. [self setUI];
  46. _label.text = _contentStr;
  47. _label2.text = _label.text;
  48. CGSize sizee = [PublicObj sizeWithString:_label.text andFont:SYS_Font(15)];
  49. CGFloat withdd = MAX(self.frame.size.width,sizee.width)+20;
  50. _label.frame = CGRectMake(0.0, 0.0, withdd, self.frame.size.height);
  51. _label2.frame = CGRectMake(withdd, 0.0, withdd, self.frame.size.height);
  52. // 动画
  53. [UIView beginAnimations:@"testAnimation" context:NULL];
  54. [UIView setAnimationDuration:3.0f];
  55. [UIView setAnimationCurve:UIViewAnimationCurveLinear];
  56. [UIView setAnimationRepeatCount:999999];
  57. CGRect frame = _label.frame;
  58. frame.origin.x = -withdd;
  59. _label.frame = frame;
  60. CGRect frame2 = _label2.frame;
  61. frame2.origin.x = 0.0;
  62. _label2.frame = frame2;
  63. [UIView commitAnimations];
  64. }
  65. -(void)stopLamp {
  66. [self removeAllSubViews];
  67. }
  68. @end