// // MOGetRedPacketView.m // MiMoLive // // Created by SuperC on 2024/6/17. // #import "MOGetRedPacketView.h" #import "TYCyclePagerView.h" #import "FLAnimatedImageView.h" #import "FLAnimatedImage.h" @interface MOGetRedPacketView () @property (weak, nonatomic) IBOutlet UIView *backgoundView; @property (weak, nonatomic) IBOutlet UIView *bgView; @property (nonatomic, strong) TYCyclePagerView *pagerView;//红包轮播 @property (nonatomic, strong) NSArray *dataArr; @property (nonatomic, strong) FLAnimatedImageView *animationView; @end @implementation MOGetRedPacketView + (instancetype)moGetRedPacketView{ return [[[NSBundle mainBundle] loadNibNamed:@"MOGetRedPacketView" owner:self options:nil] firstObject]; } - (void)awakeFromNib{ [super awakeFromNib]; self.backgoundView.backgroundColor = [MOTools colorWithHexString:@"000000" alpha:0.5]; [self.bgView addSubview:self.pagerView]; [self.pagerView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.bgView); }]; [self addSubview:self.animationView]; [self.animationView mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.mas_equalTo(0); make.centerX.mas_equalTo(20); make.width.mas_equalTo(kScaleWidth(288)); make.height.mas_equalTo(kScaleWidth(598)); }]; } - (IBAction)closeBtnClick:(id)sender { [self dismissGetRedPacketView]; } - (void)showGifAnimation { self.animationView.hidden = NO; NSData *gifData = [NSData dataWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"gif_diamond_drop" ofType:@"gif"]]; FLAnimatedImage *image = [FLAnimatedImage animatedImageWithGIFData:gifData]; self.animationView.animatedImage = image; [self.animationView startAnimating]; WEAKSELF self.animationView.loopCompletionBlock = ^(NSUInteger loopCountRemaining) { [weakSelf.animationView stopAnimating]; weakSelf.animationView.hidden = YES; }; } - (void)setRedData:(MORedEnvelopesListData *)redData{ _redData = redData; NSArray *sortedArray = [redData.redEnvelopesInfo sortedArrayUsingDescriptors:@[ [NSSortDescriptor sortDescriptorWithKey:@"startTime" ascending:YES] ]]; self.dataArr = [sortedArray copy]; [self.pagerView reloadData]; } - (NSInteger)numberOfItemsInPagerView:(TYCyclePagerView *)pageView{ return self.dataArr.count; } - (UICollectionViewCell *)pagerView:(TYCyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index{ WEAKSELF MORedEnvelopesInfo *model = self.dataArr[index]; MOGetRedPacketCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:MOGetRedPacketCell_ID forIndex:index]; cell.roomId = self.roomId; cell.cellModel = model; cell.anchorId = self.anchorId; cell.openRedPacketBlock = ^(MOReceivingBaseData * _Nonnull receiveData, MORedEnvelopesInfo * _Nonnull redInfo) { // [weakSelf dismissGetRedPacketView]; weakSelf.openRedPacketBlock ? weakSelf.openRedPacketBlock(receiveData, redInfo) : nil; if (receiveData.receivedAmount > 0) { [weakSelf showGifAnimation]; } }; return cell; } - (TYCyclePagerViewLayout *)layoutForPagerView:(TYCyclePagerView *)pageView { TYCyclePagerViewLayout *layout = [[TYCyclePagerViewLayout alloc]init]; layout.itemSize = CGSizeMake(293.0, 392.0); layout.itemSpacing = 15; layout.layoutType = TYCyclePagerTransformLayoutLinear; layout.itemHorizontalCenter = YES; return layout; } - (void)pagerView:(TYCyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex { // MOLogV(@"%ld -> %ld",fromIndex,toIndex); } - (void)pagerView:(TYCyclePagerView *)pageView didSelectedItemCell:(__kindof UICollectionViewCell *)cell atIndex:(NSInteger)index{ } /// 1秒触发一次 - (void)oneSecondPassed{ MOGetRedPacketCell *cell = (MOGetRedPacketCell *)[self.pagerView curIndexCell]; [cell updateTheTimeStatue]; } - (void)showGetRedPacketView//界面显示动画 { self.frame = CGRectMake(0.0, 0.0, SCREENWIDTH, SCREENHEIGHT); //动画效果 self.bgView.transform = CGAffineTransformMakeScale(1.3, 1.3); self.bgView.alpha = 0; [UIView animateWithDuration:0.2 animations:^ { self.bgView.transform = CGAffineTransformMakeScale(1.0, 1.0); self.bgView.alpha = 1; } completion:^(BOOL finished) { }]; //不能滑动 SendNotification(@"MOShowLivePagesVCCannotScroll") [self.pagerView reloadData]; } - (void)dismissGetRedPacketView { self.dismissViewBlock ? self.dismissViewBlock() : nil; [UIView animateWithDuration:0.2 animations:^ { self.bgView.transform = CGAffineTransformMakeScale(1.3, 1.3); self.bgView.alpha = 0; } completion:^(BOOL finished) { if (finished) { [self removeFromSuperview]; } }]; //可以滑动 SendNotification(@"MOShowLivePagesVCCanScroll") } - (TYCyclePagerView *)pagerView{ if(!_pagerView){ _pagerView = [[TYCyclePagerView alloc] initWithFrame:CGRectMake(0.0, 0.0, SCREENWIDTH, 389.0)]; _pagerView.isInfiniteLoop = NO; _pagerView.autoScrollInterval = 0; _pagerView.dataSource = self; _pagerView.delegate = self; _pagerView.layout.itemHorizontalCenter = YES; _pagerView.layout.layoutType = TYCyclePagerTransformLayoutLinear; _pagerView.layout.itemSize = CGSizeMake(293, 392.0); _pagerView.layout.itemSpacing = 15.0; [_pagerView registerClass:[MOGetRedPacketCell class] forCellWithReuseIdentifier:MOGetRedPacketCell_ID]; } return _pagerView; } - (FLAnimatedImageView *)animationView { if (!_animationView) { _animationView = [[FLAnimatedImageView alloc] init]; _animationView.contentMode = UIViewContentModeScaleAspectFill; _animationView.hidden = YES; } return _animationView; } @end