MOGetRedPacketView.m 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. //
  2. // MOGetRedPacketView.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2024/6/17.
  6. //
  7. #import "MOGetRedPacketView.h"
  8. #import "TYCyclePagerView.h"
  9. #import "FLAnimatedImageView.h"
  10. #import "FLAnimatedImage.h"
  11. @interface MOGetRedPacketView ()<TYCyclePagerViewDataSource,TYCyclePagerViewDelegate>
  12. @property (weak, nonatomic) IBOutlet UIView *backgoundView;
  13. @property (weak, nonatomic) IBOutlet UIView *bgView;
  14. @property (nonatomic, strong) TYCyclePagerView *pagerView;//红包轮播
  15. @property (nonatomic, strong) NSArray *dataArr;
  16. @property (nonatomic, strong) FLAnimatedImageView *animationView;
  17. @end
  18. @implementation MOGetRedPacketView
  19. + (instancetype)moGetRedPacketView{
  20. return [[[NSBundle mainBundle] loadNibNamed:@"MOGetRedPacketView" owner:self options:nil] firstObject];
  21. }
  22. - (void)awakeFromNib{
  23. [super awakeFromNib];
  24. self.backgoundView.backgroundColor = [MOTools colorWithHexString:@"000000" alpha:0.5];
  25. [self.bgView addSubview:self.pagerView];
  26. [self.pagerView mas_makeConstraints:^(MASConstraintMaker *make) {
  27. make.edges.equalTo(self.bgView);
  28. }];
  29. [self addSubview:self.animationView];
  30. [self.animationView mas_makeConstraints:^(MASConstraintMaker *make) {
  31. make.bottom.mas_equalTo(0);
  32. make.centerX.mas_equalTo(20);
  33. make.width.mas_equalTo(kScaleWidth(288));
  34. make.height.mas_equalTo(kScaleWidth(598));
  35. }];
  36. }
  37. - (IBAction)closeBtnClick:(id)sender {
  38. [self dismissGetRedPacketView];
  39. }
  40. - (void)showGifAnimation {
  41. self.animationView.hidden = NO;
  42. NSData *gifData = [NSData dataWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"gif_diamond_drop" ofType:@"gif"]];
  43. FLAnimatedImage *image = [FLAnimatedImage animatedImageWithGIFData:gifData];
  44. self.animationView.animatedImage = image;
  45. [self.animationView startAnimating];
  46. WEAKSELF
  47. self.animationView.loopCompletionBlock = ^(NSUInteger loopCountRemaining) {
  48. [weakSelf.animationView stopAnimating];
  49. weakSelf.animationView.hidden = YES;
  50. };
  51. }
  52. - (void)setRedData:(MORedEnvelopesListData *)redData{
  53. _redData = redData;
  54. NSArray *sortedArray = [redData.redEnvelopesInfo sortedArrayUsingDescriptors:@[
  55. [NSSortDescriptor sortDescriptorWithKey:@"startTime" ascending:YES]
  56. ]];
  57. self.dataArr = [sortedArray copy];
  58. [self.pagerView reloadData];
  59. }
  60. - (NSInteger)numberOfItemsInPagerView:(TYCyclePagerView *)pageView{
  61. return self.dataArr.count;
  62. }
  63. - (UICollectionViewCell *)pagerView:(TYCyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index{
  64. WEAKSELF
  65. MORedEnvelopesInfo *model = self.dataArr[index];
  66. MOGetRedPacketCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:MOGetRedPacketCell_ID forIndex:index];
  67. cell.roomId = self.roomId;
  68. cell.cellModel = model;
  69. cell.anchorId = self.anchorId;
  70. cell.openRedPacketBlock = ^(MOReceivingBaseData * _Nonnull receiveData, MORedEnvelopesInfo * _Nonnull redInfo) {
  71. // [weakSelf dismissGetRedPacketView];
  72. weakSelf.openRedPacketBlock ? weakSelf.openRedPacketBlock(receiveData, redInfo) : nil;
  73. if (receiveData.receivedAmount > 0) {
  74. [weakSelf showGifAnimation];
  75. }
  76. };
  77. return cell;
  78. }
  79. - (TYCyclePagerViewLayout *)layoutForPagerView:(TYCyclePagerView *)pageView {
  80. TYCyclePagerViewLayout *layout = [[TYCyclePagerViewLayout alloc]init];
  81. layout.itemSize = CGSizeMake(293.0, 392.0);
  82. layout.itemSpacing = 15;
  83. layout.layoutType = TYCyclePagerTransformLayoutLinear;
  84. layout.itemHorizontalCenter = YES;
  85. return layout;
  86. }
  87. - (void)pagerView:(TYCyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex {
  88. // MOLogV(@"%ld -> %ld",fromIndex,toIndex);
  89. }
  90. - (void)pagerView:(TYCyclePagerView *)pageView didSelectedItemCell:(__kindof UICollectionViewCell *)cell atIndex:(NSInteger)index{
  91. }
  92. /// 1秒触发一次
  93. - (void)oneSecondPassed{
  94. MOGetRedPacketCell *cell = (MOGetRedPacketCell *)[self.pagerView curIndexCell];
  95. [cell updateTheTimeStatue];
  96. }
  97. - (void)showGetRedPacketView//界面显示动画
  98. {
  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. SendNotification(@"MOShowLivePagesVCCannotScroll")
  112. [self.pagerView reloadData];
  113. }
  114. - (void)dismissGetRedPacketView
  115. {
  116. self.dismissViewBlock ? self.dismissViewBlock() : nil;
  117. [UIView animateWithDuration:0.2 animations:^
  118. {
  119. self.bgView.transform = CGAffineTransformMakeScale(1.3, 1.3);
  120. self.bgView.alpha = 0;
  121. } completion:^(BOOL finished)
  122. {
  123. if (finished)
  124. {
  125. [self removeFromSuperview];
  126. }
  127. }];
  128. //可以滑动
  129. SendNotification(@"MOShowLivePagesVCCanScroll")
  130. }
  131. - (TYCyclePagerView *)pagerView{
  132. if(!_pagerView){
  133. _pagerView = [[TYCyclePagerView alloc] initWithFrame:CGRectMake(0.0, 0.0, SCREENWIDTH, 389.0)];
  134. _pagerView.isInfiniteLoop = NO;
  135. _pagerView.autoScrollInterval = 0;
  136. _pagerView.dataSource = self;
  137. _pagerView.delegate = self;
  138. _pagerView.layout.itemHorizontalCenter = YES;
  139. _pagerView.layout.layoutType = TYCyclePagerTransformLayoutLinear;
  140. _pagerView.layout.itemSize = CGSizeMake(293, 392.0);
  141. _pagerView.layout.itemSpacing = 15.0;
  142. [_pagerView registerClass:[MOGetRedPacketCell class] forCellWithReuseIdentifier:MOGetRedPacketCell_ID];
  143. }
  144. return _pagerView;
  145. }
  146. - (FLAnimatedImageView *)animationView {
  147. if (!_animationView) {
  148. _animationView = [[FLAnimatedImageView alloc] init];
  149. _animationView.contentMode = UIViewContentModeScaleAspectFill;
  150. _animationView.hidden = YES;
  151. }
  152. return _animationView;
  153. }
  154. @end