MOGetGiftView.m 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //
  2. // MOGetGiftView.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2024/6/4.
  6. //
  7. #import "MOGetGiftView.h"
  8. #import "MOSignInGiftCell.h"
  9. #import "MOWebViewController.h"
  10. @interface MOGetGiftView ()<UICollectionViewDelegate,UICollectionViewDataSource>
  11. @property (weak, nonatomic) IBOutlet UIView *bgView;
  12. @property (weak, nonatomic) IBOutlet UILabel *titleLab;
  13. @property (weak, nonatomic) IBOutlet UILabel *dayNumLab;
  14. @property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
  15. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *collectionViewWidth;
  16. @property (weak, nonatomic) IBOutlet UIButton *signInBtn;
  17. /** 数据源 */
  18. @property (nonatomic, strong) NSMutableArray *dataArr;
  19. @end
  20. @implementation MOGetGiftView
  21. + (instancetype)moGetGiftView{
  22. return [[[NSBundle mainBundle] loadNibNamed:@"MOGetGiftView" owner:self options:nil] firstObject];
  23. }
  24. - (void)awakeFromNib{
  25. [super awakeFromNib];
  26. [self.signInBtn setBackgroundColor:kBaseBtnBgColor];
  27. self.signInBtn.layer.cornerRadius = 36.0 / 2.0;
  28. self.signInBtn.layer.masksToBounds = YES;
  29. UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
  30. flow.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  31. CGFloat width = 66.0;
  32. CGFloat height = 74.0;
  33. flow.itemSize = CGSizeMake(width, height);
  34. flow.minimumLineSpacing = 5.0;//行间距
  35. flow.minimumInteritemSpacing = 0.0;//列间距
  36. [self.collectionView setCollectionViewLayout:flow];
  37. self.collectionView.delegate = self;
  38. self.collectionView.dataSource = self;
  39. self.collectionView.backgroundColor = [UIColor clearColor];
  40. [self.collectionView registerNib:[UINib nibWithNibName:@"MOSignInGiftCell" bundle:nil] forCellWithReuseIdentifier:MOSignInGiftCell_ID];
  41. self.dayNumLab.text = NSLocalString(@"mimo_sign_in_get_more_reward_tip");
  42. [self.signInBtn setTitle:NSLocalString(@"mimo_sign_in_more_task_btn") forState:UIControlStateNormal];
  43. [self.signInBtn setFont:[MOTextTools getTheFontWithSize:16.0 AndFontName:kNormalContentFontStr]];
  44. self.dayNumLab.font = [MOTextTools getTheFontWithSize:16.0 AndFontName:kNormalContentFontStr];
  45. self.titleLab.font = [MOTextTools getTheFontWithSize:24.0 AndFontName:kNormalContentFontStr];
  46. }
  47. - (IBAction)closeBtnClick:(id)sender {
  48. [self dismissGetGiftView];
  49. }
  50. - (IBAction)moreTaskBtnClick:(id)sender {
  51. [self dismissGetGiftView];
  52. UIViewController *currentVC = [MOTools currentViewController];
  53. MOWebViewController *vc = [[MOWebViewController alloc] init];
  54. NSString *urlStr = [NSString stringWithFormat:@"%@/#/taskCenter?tagName=dailyTasks",kNetPath_Web_Base];
  55. vc.webUrl = [NSURL URLWithString:urlStr];
  56. vc.hidesBottomBarWhenPushed = YES;
  57. [currentVC.navigationController pushViewController:vc animated:YES];
  58. }
  59. - (void)setViewModel:(TaskPublishEvent *)viewModel{
  60. _viewModel = viewModel;
  61. self.titleLab.text = viewModel.n;
  62. self.dataArr = [viewModel.l copy];
  63. CGFloat theMaxWidth = 296.0 - 25.0 * 2.0;
  64. CGFloat theNeedWidth = self.dataArr.count * (66.0 + 5.0);
  65. if(theNeedWidth > theMaxWidth){
  66. theNeedWidth = theMaxWidth;
  67. }
  68. self.collectionViewWidth.constant = theNeedWidth;
  69. [self.collectionView reloadData];
  70. }
  71. #pragma mark UICollectionViewDelegate,UICollectionViewDataSource
  72. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  73. {
  74. return 1;
  75. }
  76. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  77. {
  78. return self.dataArr.count;
  79. }
  80. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  81. TaskPublishPrize *model = self.dataArr[indexPath.row];
  82. MOSignInGiftCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:MOSignInGiftCell_ID forIndexPath:indexPath];
  83. cell.pubModel = model;
  84. return cell;
  85. }
  86. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  87. [collectionView deselectItemAtIndexPath:indexPath animated:YES];
  88. }
  89. - (NSMutableArray *)dataArr{
  90. if(!_dataArr){
  91. _dataArr = [NSMutableArray array];
  92. }
  93. return _dataArr;
  94. }
  95. - (void)showGetGiftView//界面显示动画
  96. {
  97. UIWindow *keyWindow = [[UIApplication sharedApplication] delegate].window;
  98. [keyWindow addSubview:self];
  99. self.frame = CGRectMake(0.0, 0.0, SCREENWIDTH, SCREENHEIGHT);
  100. //动画效果
  101. self.bgView.transform = CGAffineTransformMakeScale(1.3, 1.3);
  102. self.bgView.alpha = 0;
  103. [UIView animateWithDuration:0.2 animations:^
  104. {
  105. self.bgView.transform = CGAffineTransformMakeScale(1.0, 1.0);
  106. self.bgView.alpha = 1;
  107. } completion:^(BOOL finished)
  108. {
  109. }];
  110. }
  111. - (void)dismissGetGiftView
  112. {
  113. [UIView animateWithDuration:0.2 animations:^
  114. {
  115. self.bgView.transform = CGAffineTransformMakeScale(1.3, 1.3);
  116. self.bgView.alpha = 0;
  117. } completion:^(BOOL finished)
  118. {
  119. if (finished)
  120. {
  121. [self removeFromSuperview];
  122. }
  123. }];
  124. }
  125. @end