YOUPAILZChatRoomGiftView.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //
  2. // YOUPAILZChatRoomGiftView.m
  3. // VQU
  4. //
  5. // Created by CY on 2021/11/17.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAILZChatRoomGiftView.h"
  9. @interface YOUPAILZChatRoomGiftView ()
  10. @property (nonatomic, weak)UILabel *youpaipcountL;
  11. @property (nonatomic, strong) NSTimer *youpaiptimer;
  12. @property (nonatomic, assign) NSInteger youpaiptimerCount;
  13. @property (nonatomic, strong,readwrite) YOUPAILZLiveGIftModel *youpaipgiftModel;
  14. @end
  15. @implementation YOUPAILZChatRoomGiftView
  16. + (instancetype)youpaifgiftViewWithModel:(YOUPAILZLiveGIftModel *)model{
  17. return [[self alloc] initWithModel:model];
  18. }
  19. - (instancetype)initWithModel:(YOUPAILZLiveGIftModel *)model{
  20. if (self = [super init]) {
  21. _youpaipgiftModel = model;
  22. [self youpaifinitUI];
  23. }
  24. return self;
  25. }
  26. - (void)youpaifinitUI{
  27. UIImageView *bgV = [[UIImageView alloc] init];
  28. UIImage *bgimg = [UIImage imageNamed:@"vqu_images_chatroom_giftbox_bg"];
  29. bgV.image = [bgimg resizableImageWithCapInsets:UIEdgeInsetsMake(0, 181, 0, 0) resizingMode:UIImageResizingModeStretch];
  30. [self addSubview:bgV];
  31. [bgV mas_makeConstraints:^(MASConstraintMaker *make) {
  32. make.left.top.bottom.right.offset(0.0f);
  33. make.height.offset(40.0f);
  34. // make.size.mas_offset(CGSizeMake(182.0f, 40.0f));
  35. }];
  36. UIImageView *avatarImgV = [[UIImageView alloc] init];
  37. avatarImgV.contentMode = UIViewContentModeScaleAspectFill;
  38. avatarImgV.layer.cornerRadius = 17.0f;
  39. avatarImgV.clipsToBounds = YES;
  40. [avatarImgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.youpaipgiftModel.youpaipavatar]];
  41. [self addSubview:avatarImgV];
  42. [avatarImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.left.offset(4.0f);
  44. make.centerY.equalTo(self);
  45. make.size.mas_offset(CGSizeMake(34.0f, 34.0f));
  46. }];
  47. UILabel *from_nicknameL = [[UILabel alloc] init];
  48. from_nicknameL.font = LCFont(12.0f);
  49. from_nicknameL.textColor = [UIColor whiteColor];
  50. from_nicknameL.text = self.youpaipgiftModel.youpaipnickName;
  51. [self addSubview:from_nicknameL];
  52. [from_nicknameL mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.top.offset(4.5f);
  54. make.left.equalTo(avatarImgV.mas_right).offset(5.0f);
  55. make.height.offset(13.0f);
  56. make.width.offset(82.0f);
  57. }];
  58. UILabel *to_nicknameL = [[UILabel alloc] init];
  59. to_nicknameL.font = LCBoldFont(12.0f);
  60. to_nicknameL.textColor = [UIColor whiteColor];
  61. to_nicknameL.attributedText = [LCTools setRichTextWithTitle:@"送给 " subTitle:self.youpaipgiftModel.youpaipto_nickName?:@"" titleColor:[[UIColor whiteColor] colorWithAlphaComponent:0.6f] subTitleColor:[UIColor whiteColor] titleFontSize:9.0f subTitleFontSize:12.0f];
  62. [self addSubview:to_nicknameL];
  63. [to_nicknameL mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.top.equalTo(from_nicknameL.mas_bottom).offset(6.5f);
  65. make.left.equalTo(avatarImgV.mas_right).offset(5.0f);
  66. make.height.offset(13.0f);
  67. make.width.offset(82.0f);
  68. }];
  69. UIImageView *giftImgV = [[UIImageView alloc] init];
  70. [giftImgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.youpaipgiftModel.youpaipgiftImage]];
  71. [self addSubview:giftImgV];
  72. [giftImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  73. make.left.equalTo(from_nicknameL.mas_right).offset(11.0f);
  74. make.centerY.equalTo(self);
  75. make.size.mas_offset(CGSizeMake(34.0f, 34.0f));
  76. }];
  77. UILabel *youpaipcountL = [[UILabel alloc] init];
  78. youpaipcountL.font = LCBoldFont(30.0f);
  79. youpaipcountL.textColor = [UIColor whiteColor];
  80. youpaipcountL.text = [NSString stringWithFormat:@"x%@",@(self.youpaipgiftModel.youpaipgiftCount)];
  81. [self addSubview:youpaipcountL];
  82. self.youpaipcountL = youpaipcountL;
  83. [youpaipcountL mas_makeConstraints:^(MASConstraintMaker *make) {
  84. make.top.bottom.right.offset(0.0f);
  85. make.left.equalTo(giftImgV.mas_right).offset(14.0f);
  86. }];
  87. }
  88. - (void)youpaifshowAnimation{
  89. [self youpaifstartTimer];
  90. if (self != nil && self.superview != nil) {
  91. [self.superview setNeedsUpdateConstraints];
  92. [self mas_updateConstraints:^(MASConstraintMaker *make) {
  93. make.left.offset(14.0f);
  94. }];
  95. }
  96. [UIView animateWithDuration:0.25f animations:^{
  97. [self.superview layoutIfNeeded];
  98. }];
  99. }
  100. - (void)youpaifhideAnimation{
  101. if (self != nil && self.superview != nil) {
  102. [self.superview setNeedsUpdateConstraints];
  103. [self mas_updateConstraints:^(MASConstraintMaker *make) {
  104. make.left.offset(-200.0f);
  105. }];
  106. }
  107. [UIView animateWithDuration:0.25f animations:^{
  108. [self.superview layoutIfNeeded];
  109. } completion:^(BOOL finished) {
  110. if ([self.delegate respondsToSelector:@selector(youpaifanimatiomFinishWithView:)]) {
  111. [self.delegate youpaifanimatiomFinishWithView:self];
  112. }
  113. }];
  114. }
  115. - (void)youpaifupdateGiftCount:(NSInteger)count{
  116. [self youpaifstopTimer];
  117. self.youpaipgiftModel.youpaipgiftCount += count;
  118. self.youpaipcountL.text = [NSString stringWithFormat:@"x %@",@(self.youpaipgiftModel.youpaipgiftCount)];
  119. [self youpaifstartTimer];
  120. }
  121. - (void)youpaifstartTimer{
  122. self.youpaiptimerCount = 2;
  123. self.youpaiptimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(youpaifcountDown) userInfo:nil repeats:YES];
  124. [[NSRunLoop currentRunLoop] addTimer:self.youpaiptimer forMode:NSRunLoopCommonModes];
  125. }
  126. - (void)youpaifstopTimer{
  127. [self.youpaiptimer invalidate];
  128. self.youpaiptimer = nil;
  129. }
  130. - (void)youpaifcountDown{
  131. self.youpaiptimerCount --;
  132. if (self.youpaiptimerCount <= 0) {
  133. [self youpaifstopTimer];
  134. [self youpaifhideAnimation];
  135. }
  136. }
  137. @end