YBUserEnterAnimation.m 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. //
  2. // YBUserEnterAnimation.m
  3. // YBVideo
  4. //
  5. // Created by YB007 on 2019/12/3.
  6. // Copyright © 2019 cat. All rights reserved.
  7. //
  8. #import "YBUserEnterAnimation.h"
  9. #import "UIView+LBExtension.h"
  10. @interface YBUserEnterAnimation()
  11. @property(nonatomic,strong)UIImageView *vipimage;
  12. @property(nonatomic,strong)UIImageView *userMoveImageV; //进入动画背景
  13. @property(nonatomic,strong)UIView *msgView; //显示用户信息
  14. @property(nonatomic,assign)int isUserMove; // 限制用户进入动画
  15. @property(nonatomic,strong)NSMutableArray *userLogin; //用户进入数组,存放动画
  16. @end
  17. @implementation YBUserEnterAnimation
  18. - (instancetype)init {
  19. self = [super init];
  20. if (self) {
  21. _isUserMove = 0;
  22. _userLogin = [NSMutableArray array];
  23. }
  24. return self;
  25. }
  26. -(void)addUserMove:(NSDictionary *)msg{
  27. if (msg) {
  28. [_userLogin addObject:msg];
  29. }
  30. if(_isUserMove == 0){
  31. [self userLoginOne];
  32. }
  33. }
  34. -(void)userLoginOne{
  35. if (_userLogin.count == 0 || _userLogin == nil) {
  36. return;
  37. }
  38. NSDictionary *Dic = [_userLogin firstObject];
  39. [_userLogin removeObjectAtIndex:0];
  40. [self userPlar:Dic];
  41. }
  42. /*
  43. vip_type vip预留功能,目前只有守护
  44. */
  45. -(void)userPlar:(NSDictionary *)dic{
  46. _isUserMove = 1;
  47. _userMoveImageV = [[UIImageView alloc]initWithFrame:CGRectMake(_window_width + 20,0, _window_width*0.8,40)];
  48. [_userMoveImageV setImage:[UIImage imageNamed:@"userlogin_Back"]];
  49. [self addSubview:_userMoveImageV];
  50. _msgView = [[UIView alloc]initWithFrame:CGRectMake(-_window_width, 0, _window_width, 40)];
  51. _msgView.backgroundColor = [UIColor clearColor];
  52. [self addSubview:_msgView];
  53. NSDictionary *ct = [dic valueForKey:@"ct"];
  54. UIImageView *iconImgView = [[UIImageView alloc]initWithFrame:CGRectMake(5, 5, 30, 30)];
  55. iconImgView.layer.cornerRadius = 15.0;
  56. iconImgView.layer.masksToBounds =YES;
  57. iconImgView.layer.borderColor = [UIColor whiteColor].CGColor;
  58. iconImgView.layer.borderWidth = 1;
  59. [iconImgView sd_setImageWithURL:[NSURL URLWithString:minstr([ct valueForKey:@"avatar"])] placeholderImage:[UIImage imageNamed:@"bg1"]];
  60. [_msgView addSubview:iconImgView];
  61. UIImageView *starImgView = [[UIImageView alloc]initWithFrame:CGRectMake(34, 19, 8, 8)];
  62. starImgView.image = [UIImage imageNamed:@"loginStar"];
  63. [_msgView addSubview:starImgView];
  64. //
  65. UILabel *nameL = [[UILabel alloc]initWithFrame:CGRectMake(iconImgView.right + 3,5,_window_width*0.8-40,30)];
  66. nameL.textColor = [UIColor whiteColor];
  67. nameL.font = [UIFont systemFontOfSize:13];
  68. NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ %@",[ct valueForKey:@"user_nickname"],YZMsg(@"进入了直播间")]];
  69. NSAttributedString *speaceString = [[NSAttributedString alloc]initWithString:@" "];
  70. //vip
  71. NSTextAttachment *vipAttchment = [[NSTextAttachment alloc]init];
  72. vipAttchment.bounds = CGRectMake(0, -2, 30, 15);//设置frame
  73. vipAttchment.image = [UIImage imageNamed:@"chat_vip"];//设置图片
  74. NSAttributedString *vipString = [NSAttributedString attributedStringWithAttachment:(NSTextAttachment *)(vipAttchment)];
  75. //守护
  76. NSTextAttachment *shouAttchment = [[NSTextAttachment alloc]init];
  77. shouAttchment.bounds = CGRectMake(0, -2, 15, 15);//设置frame
  78. shouAttchment.image = [UIImage imageNamed:getImagename(@"chat_shou_month")];//设置图片
  79. NSAttributedString *shouString = [NSAttributedString attributedStringWithAttachment:(NSTextAttachment *)(shouAttchment)];
  80. NSTextAttachment *yearAttchment = [[NSTextAttachment alloc]init];
  81. yearAttchment.bounds = CGRectMake(0, -2, 15, 15);//设置frame
  82. yearAttchment.image = [UIImage imageNamed:getImagename(@"chat_shou_year")];//设置图片
  83. NSAttributedString *yearString = [NSAttributedString attributedStringWithAttachment:(NSTextAttachment *)(yearAttchment)];
  84. if ([minstr([ct valueForKey:@"vip_type"])isEqual:@"1"]) {
  85. //插入VIP图标
  86. [noteStr insertAttributedString:speaceString atIndex:0];//插入到第几个下标
  87. [noteStr insertAttributedString:vipString atIndex:0];//插入到第几个下标
  88. }
  89. if ([minstr([ct valueForKey:@"guard_type"]) isEqual:@"1"]) {
  90. //插入月守护
  91. [noteStr insertAttributedString:speaceString atIndex:0];//插入到第几个下标
  92. [noteStr insertAttributedString:shouString atIndex:0];//插入到第几个下标
  93. }
  94. if ([minstr([ct valueForKey:@"guard_type"]) isEqual:@"2"]) {
  95. //插入年守护
  96. [noteStr insertAttributedString:speaceString atIndex:0];//插入到第几个下标
  97. [noteStr insertAttributedString:yearString atIndex:0];//插入到第几个下标
  98. }
  99. [noteStr insertAttributedString:speaceString atIndex:0];//插入到第几个下标
  100. [nameL setAttributedText:noteStr];
  101. [_msgView addSubview:nameL];
  102. CGMutablePathRef path = CGPathCreateMutable();
  103. //CGPathAddArc函数是通过圆心和半径定义一个圆,然后通过两个弧度确定一个弧线。注意弧度是以当前坐标环境的X轴开始的。
  104. //需要注意的是由于ios中的坐标体系是和Quartz坐标体系中Y轴相反的,所以iOS UIView在做Quartz绘图时,Y轴已经做了Scale为-1的转换,因此造成CGPathAddArc函数最后一个是否是顺时针的参数结果正好是相反的,也就是说如果设置最后的参数为1,根据参数定义应该是顺时针的,但实际绘图结果会是逆时针的!
  105. //严格的说,这个方法只是确定一个中心点后,以某个长度作为半径,以确定的角度和顺逆时针而进行旋转,半径最低设置为1,设置为0则动画不会执行
  106. CGPathAddArc(path, NULL, iconImgView.centerX, iconImgView.centerY, 16, 0,M_PI * 2, 0);
  107. CAKeyframeAnimation * animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
  108. animation.path = path;
  109. CGPathRelease(path);
  110. animation.duration = 3;
  111. animation.repeatCount = 1;
  112. animation.autoreverses = NO;
  113. animation.rotationMode =kCAAnimationRotateAuto;
  114. animation.fillMode =kCAFillModeForwards;
  115. [UIView animateWithDuration:0.5 animations:^{
  116. _userMoveImageV.x = 80;
  117. _msgView.x = 80;
  118. }completion:^(BOOL finished) {
  119. [starImgView.layer addAnimation:animation forKey:nil];
  120. }];
  121. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  122. [UIView animateWithDuration:1.5 animations:^{
  123. _userMoveImageV.x = 10;
  124. _msgView.x = 10;
  125. }] ;
  126. });
  127. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  128. [UIView animateWithDuration:0.5 animations:^{
  129. _userMoveImageV.x = -_window_width;
  130. _msgView.x = _window_width;
  131. } completion:^(BOOL finished) {
  132. [_userMoveImageV removeFromSuperview];
  133. _userMoveImageV = nil;
  134. [_msgView removeFromSuperview];
  135. _msgView = nil;
  136. _isUserMove = 0;
  137. if (_userLogin.count >0) {
  138. [self addUserMove:nil];
  139. }
  140. }];
  141. });
  142. }
  143. -(void)removeAnimation {
  144. if (_userMoveImageV) {
  145. [_userMoveImageV removeFromSuperview];
  146. _userMoveImageV = nil;
  147. }
  148. if (_msgView) {
  149. [_msgView removeFromSuperview];
  150. _msgView = nil;
  151. }
  152. }
  153. @end