diff --git a/YuMi/Modules/ShoppingMall/ShoppingMallCategoryListView.h b/YuMi/Modules/ShoppingMall/ShoppingMallCategoryListView.h index 781d467b..ea717c2f 100644 --- a/YuMi/Modules/ShoppingMall/ShoppingMallCategoryListView.h +++ b/YuMi/Modules/ShoppingMall/ShoppingMallCategoryListView.h @@ -11,6 +11,7 @@ NS_ASSUME_NONNULL_BEGIN +typedef void (^DidTapPlay)(NSString *resourcePath); typedef void (^FetchDataCompletion)(NSArray * modelList); typedef void (^FetchDataForPage)(NSInteger pageIndex, FetchDataCompletion completion); @@ -20,7 +21,7 @@ typedef void (^FetchDataForPage)(NSInteger pageIndex, FetchDataCompletion comple // 名称:类型 @property (nonatomic, copy) NSArray *> *items; @property (nonatomic, copy) FetchDataForPage fetchDataForPage; - +@property (nonatomic, copy) DidTapPlay didTapItemPlay; @end diff --git a/YuMi/Modules/ShoppingMall/ShoppingMallCategoryListView.m b/YuMi/Modules/ShoppingMall/ShoppingMallCategoryListView.m index a84371e7..a10b0ab2 100644 --- a/YuMi/Modules/ShoppingMall/ShoppingMallCategoryListView.m +++ b/YuMi/Modules/ShoppingMall/ShoppingMallCategoryListView.m @@ -20,6 +20,8 @@ @property (nonatomic, strong) UILabel *description_2_label; @property (nonatomic, strong) UILabel *statusLabel; +@property (nonatomic, copy) DidTapPlay didTapPlay; + @end @implementation ShoppingMallItemCard @@ -77,7 +79,7 @@ make.leading.mas_equalTo(self.bgImageView).offset(1); make.bottom.trailing.mas_equalTo(self.bgImageView).offset(-1); make.height.mas_equalTo(45); - }]; + }]; [self.contentView addSubview:self.statusLabel]; [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) { @@ -97,10 +99,14 @@ self.description_1_label.text = YMLocalizedString(@"1.0.30_text_1"); self.description_2_label.text = YMLocalizedString(@"1.0.30_text_2"); self.statusLabel.text = @"FFUFUFUFUFUFUFUFUUFUFUCKCKCKCKKCKCKCKCKCKCK";//YMLocalizedString(@"1.0.30_text_4"); + + self.playButton.hidden = !([cellModel.effect.lowercaseString hasSuffix:@"svga"] || [cellModel.effect.lowercaseString hasSuffix:@"mp4"]); } - (void)handleTapPlay:(id)sender { - + if (_didTapPlay) { + self.didTapPlay(self.cellModel.effect); + } } #pragma mark - @@ -475,7 +481,13 @@ forIndexPath:indexPath]; NSArray *data = self.dataCache[@(collectionView.tag)]; cell.cellModel = [data xpSafeObjectAtIndex:indexPath.row]; - + if (self.didTapItemPlay) { + @kWeakify(self); + cell.didTapPlay = ^(NSString * _Nonnull resourcePath) { + @kStrongify(self); + self.didTapItemPlay(resourcePath); + }; + } return cell; } diff --git a/YuMi/Modules/ShoppingMall/ShoppingMallViewController.m b/YuMi/Modules/ShoppingMall/ShoppingMallViewController.m index 15823fbe..2c9b50b4 100644 --- a/YuMi/Modules/ShoppingMall/ShoppingMallViewController.m +++ b/YuMi/Modules/ShoppingMall/ShoppingMallViewController.m @@ -7,11 +7,18 @@ #import "ShoppingMallViewController.h" +#import +#import + #import "ShoppingMallDataPresent.h" #import "ShoppingMallCategoryListView.h" @interface ShoppingMallViewController () +@property (nonatomic, strong) UIView *playEffectMask; +@property (nonatomic, strong) VAPView *mp4Effect; +@property (nonatomic, strong) SVGAImageView *svgaEffect; + @end @implementation ShoppingMallViewController @@ -44,6 +51,10 @@ @kStrongify(self); [self fetchDataForPage:pageIndex completion:completion]; }; + listView.didTapItemPlay = ^(NSString * _Nonnull resourcePath) { + @kStrongify(self); + [self playItemEffect:resourcePath]; + }; [self.view addSubview:listView]; listView.items = @[@{YMLocalizedString(@"XPMineDressUpViewController2") : @1}, // 座驾 @@ -65,4 +76,63 @@ }]; } +- (void)playItemEffect:(NSString *)path { + if ([path.lowercaseString hasSuffix:@"svga"]) { + @kWeakify(self); + SVGAParser *p = [[SVGAParser alloc] init]; + [p parseWithURL:[NSURL URLWithString:path] + completionBlock:^(SVGAVideoEntity * _Nullable videoItem) { + @kStrongify(self); + self.svgaEffect.hidden = NO; + self.svgaEffect.videoItem = videoItem; + [self.svgaEffect startAnimation]; + } failureBlock:^(NSError * _Nullable error) { + + }]; + } else if ([path.lowercaseString hasSuffix:@"mp4"]) { + + } +} + +- (void)stopItemSVGAEffect { + [self.svgaEffect stopAnimation]; + self.svgaEffect.hidden = YES; + self.playEffectMask.hidden = YES; +} + + +#pragma mark - +- (UIView *)playEffectMask { + if (!_playEffectMask) { + _playEffectMask = [[UIView alloc] initWithFrame:self.view.bounds]; + _playEffectMask.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5f]; + } + return _playEffectMask; +} + +- (SVGAImageView *)svgaEffect { + if (!_svgaEffect) { + _svgaEffect = [[SVGAImageView alloc] init]; + _svgaEffect.contentMode = UIViewContentModeScaleAspectFit; + _svgaEffect.autoPlay = YES; + _svgaEffect.loops = 0; + _svgaEffect.clearsAfterStop = YES; + _svgaEffect.hidden = YES; + + if (!_playEffectMask) { + [self.view addSubview:self.playEffectMask]; + } + + [self.view addSubview:_svgaEffect]; + [_svgaEffect mas_makeConstraints:^(MASConstraintMaker *make) { + make.bottom.leading.trailing.mas_equalTo(self.view); + make.height.mas_equalTo(KScreenHeight - 100); + }]; + + UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(stopItemSVGAEffect)]; + [_svgaEffect addGestureRecognizer:tap]; + } + return _svgaEffect; +} + @end