MOActivityRewardView.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. //
  2. // MOActivityRewardView.m
  3. // MiMoLive
  4. //
  5. // Created by MiMo on 2025/5/23.
  6. //
  7. #import "MOActivityRewardView.h"
  8. @interface MOActivityRewarItemView ()
  9. @property (nonatomic, strong) UIImageView *iconImgView;
  10. @property (nonatomic, strong) UIImageView *coverImgView;
  11. @property (nonatomic, strong) UILabel *amountLabel;
  12. @property (nonatomic, strong) UILabel *nameLabel;
  13. @end
  14. @implementation MOActivityRewarItemView
  15. - (instancetype)init {
  16. if (self = [super init]) {
  17. [self setupUI];
  18. }
  19. return self;
  20. }
  21. - (void)setupImageUrl:(NSString *)imageUrl amountText:(NSString *)amountText bgUrl:(NSString *)bgUrl nameText:(NSString *)nameText iconTextColor:(NSString *)iconTextColor {
  22. [self.iconImgView sd_setImageWithURL:[NSURL URLWithString:imageUrl]];
  23. [self.coverImgView sd_setImageWithURL:[NSURL URLWithString:bgUrl]];
  24. self.amountLabel.text = amountText;
  25. self.nameLabel.text = nameText;
  26. if (iconTextColor.length > 0) {
  27. NSString *colorString = [NSString stringWithFormat:@"#%@", iconTextColor];
  28. UIColor *textColor = [MOTools colorWithHexString:colorString];
  29. self.amountLabel.textColor = textColor;
  30. self.nameLabel.textColor = textColor;
  31. }
  32. }
  33. - (void)setupUI {
  34. [self addSubview:self.coverImgView];
  35. [self.coverImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  36. make.top.mas_equalTo(0);
  37. make.centerX.mas_equalTo(0);
  38. make.width.mas_equalTo(kScaleWidth(66));
  39. make.height.mas_equalTo(kScaleWidth(66));
  40. }];
  41. [self addSubview:self.iconImgView];
  42. [self.iconImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.center.equalTo(self.coverImgView);
  44. make.width.mas_equalTo(kScaleWidth(52));
  45. make.height.mas_equalTo(kScaleWidth(52));
  46. }];
  47. [self addSubview:self.amountLabel];
  48. [self.amountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.top.equalTo(self.coverImgView.mas_bottom).offset(2);
  50. make.left.right.mas_equalTo(0);
  51. make.height.mas_equalTo(18);
  52. }];
  53. [self addSubview:self.nameLabel];
  54. [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.top.equalTo(self.amountLabel.mas_bottom);
  56. make.left.right.mas_equalTo(0);
  57. make.height.mas_equalTo(20);
  58. }];
  59. }
  60. - (UIImageView *)iconImgView {
  61. if (!_iconImgView) {
  62. _iconImgView = [[UIImageView alloc] init];
  63. _iconImgView.contentMode = UIViewContentModeScaleAspectFit;
  64. _iconImgView.clipsToBounds = YES;
  65. }
  66. return _iconImgView;
  67. }
  68. - (UIImageView *)coverImgView {
  69. if (!_coverImgView) {
  70. _coverImgView = [[UIImageView alloc] init];
  71. _coverImgView.contentMode = UIViewContentModeScaleAspectFill;
  72. }
  73. return _coverImgView;
  74. }
  75. - (UILabel *)amountLabel {
  76. if (!_amountLabel) {
  77. _amountLabel = [[UILabel alloc] init];
  78. _amountLabel.font = [MOTextTools getTheFontWithSize:14.0 AndFontName:kNormalContentBlodFontStr];
  79. _amountLabel.textColor = [MOTools colorWithHexString:@"#FFFFFF"];
  80. _amountLabel.textAlignment = NSTextAlignmentCenter;
  81. }
  82. return _amountLabel;
  83. }
  84. - (UILabel *)nameLabel {
  85. if (!_nameLabel) {
  86. _nameLabel = [[UILabel alloc] init];
  87. _nameLabel.font = [UIFont systemFontOfSize:12];
  88. _nameLabel.textColor = [MOTools colorWithHexString:@"#FFFFFF"];
  89. _nameLabel.textAlignment = NSTextAlignmentCenter;
  90. }
  91. return _nameLabel;
  92. }
  93. @end
  94. #define kMOActivityRewardViewWidth kScaleWidth(297)
  95. #define kMOActivityRewardViewHeight kScaleWidth(384)
  96. #import "MOActivityRewardView.h"
  97. @interface MOActivityRewardView ()
  98. @property (nonatomic, strong) UIView *bgView;
  99. @property (nonatomic, strong) UIImageView *bgImgView;
  100. @property (nonatomic, strong) UIStackView *awardStackkView;
  101. @property (nonatomic, strong) UIScrollView *scrollView;
  102. @property (nonatomic, strong) UIButton *okButton;
  103. @property (nonatomic, strong) UIButton *closeButton;
  104. @end
  105. @implementation MOActivityRewardView
  106. - (instancetype)init {
  107. if (self = [super init]) {
  108. [self setupUI];
  109. }
  110. return self;
  111. }
  112. - (void)setupUI {
  113. [self addSubview:self.bgView];
  114. [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  115. make.edges.mas_equalTo(0);
  116. }];
  117. [self addSubview:self.bgImgView];
  118. [self.bgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  119. make.centerX.mas_equalTo(0);
  120. make.centerY.mas_equalTo(-35);
  121. make.size.mas_equalTo(CGSizeMake(kMOActivityRewardViewWidth, kMOActivityRewardViewHeight));
  122. }];
  123. [self.bgImgView addSubview:self.scrollView];
  124. [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
  125. make.top.equalTo(self.bgImgView.mas_top).offset(kMOActivityRewardViewHeight * 0.6);
  126. make.centerX.mas_equalTo(0);
  127. make.height.mas_equalTo(kScaleWidth(66) + 40);
  128. make.width.mas_equalTo(kScaleWidth(66) * 3 + 40);
  129. }];
  130. [self.scrollView addSubview:self.awardStackkView];
  131. [self.awardStackkView mas_makeConstraints:^(MASConstraintMaker *make) {
  132. make.edges.equalTo(self.scrollView);
  133. }];
  134. [self.bgImgView addSubview:self.okButton];
  135. [self.okButton mas_makeConstraints:^(MASConstraintMaker *make) {
  136. make.left.right.bottom.mas_equalTo(0);
  137. make.height.mas_equalTo(80);
  138. }];
  139. [self addSubview:self.closeButton];
  140. [self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
  141. make.top.mas_equalTo(self.bgImgView.mas_bottom).offset(40);
  142. make.centerX.mas_equalTo(0);
  143. make.size.mas_equalTo(CGSizeMake(30, 30));
  144. }];
  145. }
  146. - (void)setModel:(MORtmUserDialog *)model {
  147. _model = model;
  148. [self.bgImgView sd_setImageWithURL:[NSURL URLWithString:model.backgroundImg]];
  149. if (model.iconItems.count == 0) {
  150. self.scrollView.hidden = YES;
  151. return;
  152. }
  153. [self.scrollView mas_updateConstraints:^(MASConstraintMaker *make) {
  154. make.top.equalTo(self.bgImgView.mas_top).offset(kMOActivityRewardViewHeight * model.giftTopNum);
  155. }];
  156. [model.iconItems enumerateObjectsUsingBlock:^(MORtmUserDialogItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  157. MOActivityRewarItemView *item = [[MOActivityRewarItemView alloc] init];
  158. if (obj.type == 1) {//钻石
  159. NSString *amountText = [NSString stringWithFormat:@"* %zd", obj.amount];
  160. [item setupImageUrl:obj.img amountText:amountText bgUrl:model.iconBackgroundImg nameText:@"" iconTextColor:model.iconTextColor];
  161. } else if (obj.type == 2) {//道具
  162. NSString *amountText = [NSString stringWithFormat:@"* %zdd", obj.amount];
  163. [item setupImageUrl:obj.img amountText:amountText bgUrl:model.iconBackgroundImg nameText:obj.name iconTextColor:model.iconTextColor];
  164. } else if (obj.type == 3) {//礼物
  165. NSString *amountText = [NSString stringWithFormat:@"* %zd", obj.amount];
  166. [item setupImageUrl:obj.img amountText:amountText bgUrl:model.iconBackgroundImg nameText:obj.name iconTextColor:model.iconTextColor];
  167. }
  168. [self.awardStackkView addArrangedSubview:item];
  169. [item mas_makeConstraints:^(MASConstraintMaker *make) {
  170. make.width.mas_equalTo(kScaleWidth(66));
  171. make.height.mas_equalTo(kScaleWidth(66) + 40);
  172. }];
  173. }];
  174. if (model.iconItems.count <= 3) {
  175. [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
  176. make.width.mas_equalTo(kScaleWidth(66) * model.iconItems.count + (15 * (model.iconItems.count - 1)));
  177. }];
  178. [self.awardStackkView setNeedsLayout];
  179. [self.awardStackkView layoutIfNeeded];
  180. } else if (model.iconItems.count > 3) {
  181. [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
  182. make.top.equalTo(self.bgImgView.mas_top).offset(kMOActivityRewardViewHeight * 0.6);
  183. make.left.mas_equalTo(25);
  184. make.right.mas_equalTo(-15);
  185. make.height.mas_equalTo(kScaleWidth(66) + 40);
  186. }];
  187. [self.awardStackkView setNeedsLayout];
  188. [self.awardStackkView layoutIfNeeded];
  189. }
  190. self.scrollView.scrollEnabled = (self.model.iconItems.count > 3);
  191. }
  192. - (void)okBtnAction {
  193. [self dismiss];
  194. }
  195. - (void)show {
  196. UIWindow *keyWindow = [[UIApplication sharedApplication] delegate].window;
  197. [keyWindow addSubview:self];
  198. self.frame = CGRectMake(0.0, 0.0, SCREENWIDTH, SCREENHEIGHT);
  199. //动画效果
  200. self.bgImgView.transform = CGAffineTransformMakeScale(1.3, 1.3);
  201. self.bgImgView.alpha = 0;
  202. [UIView animateWithDuration:0.2 animations:^ {
  203. self.bgImgView.transform = CGAffineTransformMakeScale(1.0, 1.0);
  204. self.bgImgView.alpha = 1;
  205. } completion:nil];
  206. }
  207. - (void)dismiss {
  208. [UIView animateWithDuration:0.2 animations:^ {
  209. self.bgImgView.transform = CGAffineTransformMakeScale(1.3, 1.3);
  210. self.bgImgView.alpha = 0;
  211. } completion:^(BOOL finished) {
  212. if (finished) {
  213. [self removeFromSuperview];
  214. }
  215. }];
  216. }
  217. - (UIView *)bgView {
  218. if (!_bgView) {
  219. _bgView = [[UIView alloc] init];
  220. _bgView.backgroundColor = [MOTools colorWithHexString:@"#000000" alpha:0.5];
  221. // UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismiss)];
  222. // [_bgView addGestureRecognizer:tap];
  223. }
  224. return _bgView;
  225. }
  226. - (UIImageView *)bgImgView {
  227. if (!_bgImgView) {
  228. _bgImgView = [[UIImageView alloc] init];
  229. _bgImgView.contentMode = UIViewContentModeScaleAspectFill;
  230. _bgImgView.userInteractionEnabled = YES;
  231. }
  232. return _bgImgView;
  233. }
  234. - (UIStackView *)awardStackkView {
  235. if (!_awardStackkView) {
  236. _awardStackkView = [[UIStackView alloc] init];
  237. _awardStackkView.axis = UILayoutConstraintAxisHorizontal;
  238. _awardStackkView.distribution = UIStackViewDistributionFillEqually;
  239. _awardStackkView.spacing = 15.0;
  240. }
  241. return _awardStackkView;
  242. }
  243. - (UIScrollView *)scrollView {
  244. if (!_scrollView) {
  245. _scrollView = [[UIScrollView alloc] init];
  246. _scrollView.showsVerticalScrollIndicator = NO;
  247. _scrollView.showsHorizontalScrollIndicator = NO;
  248. _scrollView.alwaysBounceVertical = NO;
  249. _scrollView.alwaysBounceHorizontal = YES;
  250. _scrollView.directionalLockEnabled = YES;
  251. }
  252. return _scrollView;
  253. }
  254. - (UIButton *)okButton {
  255. if (!_okButton) {
  256. _okButton = [[UIButton alloc] init];
  257. _okButton.backgroundColor = [UIColor clearColor];
  258. [_okButton addTarget:self action:@selector(okBtnAction) forControlEvents:UIControlEventTouchUpInside];
  259. }
  260. return _okButton;
  261. }
  262. - (UIButton *)closeButton {
  263. if (!_closeButton) {
  264. _closeButton = [[UIButton alloc] init];
  265. [_closeButton setImage:[UIImage imageNamed:@"icon_activity_reward_close"] forState:UIControlStateNormal];
  266. [_closeButton addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside];
  267. }
  268. return _closeButton;
  269. }
  270. @end