MOFastGiveView.m 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //
  2. // MOFastGiveView.m
  3. // MiMoLive
  4. //
  5. // Created by MiMo on 2025/7/27.
  6. //
  7. #import "MOFastGiveView.h"
  8. #import "MORingCountdownView.h"
  9. #import "UIImageView+Gift.h"
  10. @interface MOFastGiveView ()
  11. @property (nonatomic, strong) UIImageView *bgImgView;
  12. @property (nonatomic, strong) UIImageView *giftImgView;//礼物图片
  13. @property (nonatomic, strong) MORingCountdownView *countdownView;
  14. @property (nonatomic, assign) NSInteger addTime;//需要增加的时间
  15. @end
  16. @implementation MOFastGiveView
  17. - (instancetype)init {
  18. if (self = [super init]) {
  19. [self setupUI];
  20. }
  21. return self;
  22. }
  23. - (void)sendGiftAction {
  24. if (self.sendGiveBlock) {
  25. self.sendGiveBlock(self.fastGiveModel);
  26. }
  27. }
  28. - (void)setupUI {
  29. [self addSubview:self.bgImgView];
  30. [self.bgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  31. make.size.mas_equalTo(CGSizeMake(36, 36));
  32. make.center.mas_equalTo(0);
  33. }];
  34. [self addSubview:self.giftImgView];
  35. [self.giftImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  36. make.edges.mas_equalTo(0);
  37. }];
  38. MORingCountdownView *countdownView = [[MORingCountdownView alloc] initWithFrame:CGRectMake(0, 0, 36, 36)];
  39. WEAKSELF
  40. countdownView.stopBlock = ^{
  41. if (weakSelf.timeoutBlock) {
  42. weakSelf.timeoutBlock();
  43. }
  44. };
  45. [self.bgImgView addSubview:countdownView];
  46. self.countdownView = countdownView;
  47. self.countdownView.lineWidth = 2.0;
  48. self.countdownView.ringColor = [MOTools colorWithHexString:@"#FFF0C7"];
  49. [self.countdownView reloadAppearance];
  50. }
  51. - (void)startCountdonwWithTime:(NSInteger)time {
  52. [self.countdownView startCountdownWithDuration:time];
  53. }
  54. //动画时间再加上多长时间
  55. - (void)addCountdonwWithTime:(NSInteger)time {
  56. self.addTime += time;
  57. NSTimeInterval result = [self.countdownView elapsedAnimationTime];
  58. if (self.addTime >= 180) {
  59. self.addTime = 180;
  60. }
  61. [self.countdownView startCountdownWithDuration:self.addTime];
  62. }
  63. - (void)setFastGiveModel:(MORtmFastGive *)fastGiveModel {
  64. _fastGiveModel = fastGiveModel;
  65. [self.giftImgView mo_setGiftImageWith:fastGiveModel.giftImage];
  66. }
  67. - (UIImageView *)bgImgView {
  68. if (!_bgImgView) {
  69. _bgImgView = [[UIImageView alloc] init];
  70. _bgImgView.image = [UIImage imageNamed:@"icon_fast_give_bg"];
  71. }
  72. return _bgImgView;
  73. }
  74. - (UIImageView *)giftImgView {
  75. if (!_giftImgView) {
  76. _giftImgView = [[UIImageView alloc] init];
  77. _giftImgView.contentMode = UIViewContentModeScaleAspectFill;
  78. _giftImgView.userInteractionEnabled = YES;
  79. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(sendGiftAction)];
  80. [_giftImgView addGestureRecognizer:tap];
  81. }
  82. return _giftImgView;
  83. }
  84. @end