MOSignInAlertView.m 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. //
  2. // MOSignInAlertView.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2024/5/31.
  6. //
  7. #import "MOSignInAlertView.h"
  8. #import "MOSignInGiftCell.h"
  9. @interface MOSignInAlertView ()<UICollectionViewDelegate,UICollectionViewDataSource>
  10. @property (weak, nonatomic) IBOutlet UIView *bgView;
  11. @property (weak, nonatomic) IBOutlet UILabel *titleLab;
  12. @property (weak, nonatomic) IBOutlet UILabel *dayNumLab;
  13. @property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
  14. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *collectionViewWidth;
  15. @property (weak, nonatomic) IBOutlet UILabel *tipLab;
  16. @property (weak, nonatomic) IBOutlet UIButton *signInBtn;
  17. @property (weak, nonatomic) IBOutlet UIButton *closeBtn;
  18. /** 数据源 */
  19. @property (nonatomic, strong) NSMutableArray *dataArr;
  20. @end
  21. @implementation MOSignInAlertView
  22. + (instancetype)moSignInAlertView{
  23. return [[[NSBundle mainBundle] loadNibNamed:@"MOSignInAlertView" owner:self options:nil] firstObject];
  24. }
  25. - (void)awakeFromNib{
  26. [super awakeFromNib];
  27. [self.signInBtn setBackgroundColor:kBaseBtnBgColor];
  28. self.signInBtn.layer.cornerRadius = 36.0 / 2.0;
  29. self.signInBtn.layer.masksToBounds = YES;
  30. self.titleLab.textColor = kBaseBtnBgColor;
  31. UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
  32. flow.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  33. CGFloat width = 66.0;
  34. CGFloat height = 74.0;
  35. flow.itemSize = CGSizeMake(width, height);
  36. flow.minimumLineSpacing = 5.0;//行间距
  37. flow.minimumInteritemSpacing = 0.0;//列间距
  38. [self.collectionView setCollectionViewLayout:flow];
  39. self.collectionView.delegate = self;
  40. self.collectionView.dataSource = self;
  41. self.collectionView.backgroundColor = [UIColor clearColor];
  42. [self.collectionView registerNib:[UINib nibWithNibName:@"MOSignInGiftCell" bundle:nil] forCellWithReuseIdentifier:MOSignInGiftCell_ID];
  43. self.titleLab.text = NSLocalString(@"mimo_sign_in_title");
  44. self.dayNumLab.text = [NSString stringWithFormat:NSLocalString(@"mimo_sign_in_for_day"),0];
  45. self.tipLab.text = NSLocalString(@"mimo_sign_in_tip_two");
  46. [self.signInBtn setTitle:NSLocalString(@"mimo_sign_in_title") forState:UIControlStateNormal];
  47. [self.signInBtn setFont:[MOTextTools getTheFontWithSize:16.0 AndFontName:kNormalContentFontStr]];
  48. self.tipLab.font = [MOTextTools getTheFontWithSize:12.0 AndFontName:kNormalContentFontStr];
  49. self.dayNumLab.font = [MOTextTools getTheFontWithSize:16.0 AndFontName:kNormalContentFontStr];
  50. self.titleLab.font = [MOTextTools getTheFontWithSize:24.0 AndFontName:kNormalContentFontStr];
  51. }
  52. - (IBAction)closeBtnClick:(id)sender {
  53. [self dismissSignInAlertView];
  54. }
  55. - (IBAction)signInBtnClick:(id)sender {
  56. if(self.isGet){
  57. //已签到
  58. self.toTaskWebBlock ? self.toTaskWebBlock() : nil;
  59. [self dismissSignInAlertView];
  60. }
  61. else
  62. {
  63. //未签到
  64. [self toSignInAction];
  65. }
  66. }
  67. - (void)toSignInAction{
  68. WEAKSELF
  69. [kHttpManager toSubmitTheSignTaskAboutSignWithParams:nil andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  70. if(kCode_Success){
  71. // MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
  72. weakSelf.isGet = YES;
  73. MOSignBaseData *model = [MOSignBaseData modelObjectWithDictionary:data[@"data"]];
  74. weakSelf.baseData.continuous = model.continuous;
  75. weakSelf.baseData.signPrizes = model.signPrizes;
  76. [weakSelf updataAllUIWithProperty];
  77. //设置签到时间
  78. [MOTools setTimeOfShowSignDevice:[NSDate date]];
  79. }
  80. else{
  81. MOLogV(@"toGetTheSignTaskInfoWithParams 接口报错了");
  82. kShowNetError(data)
  83. }
  84. }];
  85. }
  86. #pragma mark UICollectionViewDelegate,UICollectionViewDataSource
  87. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  88. {
  89. return 1;
  90. }
  91. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  92. {
  93. return self.dataArr.count;
  94. }
  95. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  96. MOSignPrizes *model = self.dataArr[indexPath.row];
  97. MOSignInGiftCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:MOSignInGiftCell_ID forIndexPath:indexPath];
  98. cell.isGet = self.isGet;
  99. cell.cellModel = model;
  100. return cell;
  101. }
  102. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  103. [collectionView deselectItemAtIndexPath:indexPath animated:YES];
  104. }
  105. - (NSMutableArray *)dataArr{
  106. if(!_dataArr){
  107. _dataArr = [NSMutableArray array];
  108. }
  109. return _dataArr;
  110. }
  111. - (void)showSignInAlertView//界面显示动画
  112. {
  113. UIWindow *keyWindow = [[UIApplication sharedApplication] delegate].window;
  114. [keyWindow addSubview:self];
  115. self.frame = CGRectMake(0.0, 0.0, SCREENWIDTH, SCREENHEIGHT);
  116. //动画效果
  117. self.bgView.transform = CGAffineTransformMakeScale(1.3, 1.3);
  118. self.bgView.alpha = 0;
  119. [UIView animateWithDuration:0.2 animations:^
  120. {
  121. self.bgView.transform = CGAffineTransformMakeScale(1.0, 1.0);
  122. self.bgView.alpha = 1;
  123. } completion:^(BOOL finished)
  124. {
  125. }];
  126. }
  127. - (void)dismissSignInAlertView
  128. {
  129. [UIView animateWithDuration:0.2 animations:^
  130. {
  131. self.bgView.transform = CGAffineTransformMakeScale(1.3, 1.3);
  132. self.bgView.alpha = 0;
  133. } completion:^(BOOL finished)
  134. {
  135. if (finished)
  136. {
  137. [self removeFromSuperview];
  138. }
  139. }];
  140. }
  141. - (void)setBaseData:(MOSignBaseData *)baseData{
  142. _baseData = baseData;
  143. [self updataAllUIWithProperty];
  144. }
  145. - (void)updataAllUIWithProperty{
  146. self.dataArr = [self.baseData.signPrizes mutableCopy];
  147. CGFloat theMaxWidth = 296.0 - 25.0 * 2.0;
  148. CGFloat theNeedWidth = self.dataArr.count * (66.0 + 5.0);
  149. if(theNeedWidth > theMaxWidth){
  150. theNeedWidth = theMaxWidth;
  151. }
  152. self.collectionViewWidth.constant = theNeedWidth;
  153. [self.collectionView reloadData];
  154. NSString *signNumDayStr = [NSString stringWithFormat:NSLocalString(@"mimo_sign_in_for_day"),self.baseData.continuous];
  155. NSMutableAttributedString *plainText = [self colorfulStringWith:signNumDayStr];
  156. self.dayNumLab.attributedText = plainText;
  157. if(self.isGet){
  158. [self.signInBtn setTitle:NSLocalString(@"mimo_sign_in_more_btn") forState:UIControlStateNormal];
  159. }
  160. else{
  161. [self.signInBtn setTitle:NSLocalString(@"mimo_sign_in_title") forState:UIControlStateNormal];
  162. }
  163. }
  164. - (NSMutableAttributedString *)colorfulStringWith:(NSString *)contentStr{
  165. NSString *numStr = [NSString stringWithFormat:@"%.f",self.baseData.continuous];
  166. // 创建属性字符串,整体颜色为白色
  167. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:contentStr attributes:@{NSFontAttributeName:[MOTextTools getTheFontWithSize:16.0 AndFontName:kNormalContentFontStr],NSForegroundColorAttributeName:[MOTools colorWithHexString:@"#282828" alpha:1.0]}];
  168. NSRange redRange = [contentStr rangeOfString:numStr];
  169. if(redRange.location != NSNotFound){
  170. // 将最后三个字符的颜色设置为红色
  171. [attributedString addAttribute:NSForegroundColorAttributeName value:kBaseBtnBgColor range:redRange];
  172. }
  173. return attributedString;
  174. }
  175. @end