// // WKM_goodsBanner.m // westkissMob // // Created by 王猛 on 2022/9/14. // #import "WKM_goodsBanner.h" #import "SelectVCollectionViewCell.h" #import static NSString *const GoodsVideoCollectionViewCellID = @"GoodsVideoCollectionViewCellId"; static NSString *const GoodsBannerCollectionViewCellID = @"GoodsBannerCollectionViewCellId"; static NSString *const SelectVCollectionViewCellID = @"SelectVCollectionViewCellID"; @interface WKM_goodsBanner() @property (nonatomic, strong) NSMutableArray *dataAry; @property (nonatomic, strong) UICollectionView *collectV; @end @implementation WKM_goodsBanner - (void)tt_setupViews{ [self addSubview:self.BannerV]; [self addSubview:self.collectV]; [self.BannerV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.top.mas_equalTo(0); make.width.height.mas_equalTo(KScreenWidth); }]; [self.collectV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(10); make.right.mas_equalTo(0); make.top.equalTo(self.BannerV.mas_bottom).offset(10); make.height.mas_equalTo(112); }]; } -(void)tt_confignewdata:(id)data{ GoodsInformationM *infoModel = (GoodsInformationM *)data; NSMutableArray *imgArry =[NSMutableArray arrayWithArray:infoModel.media_gallery_entries]; NSMutableArray *modelAry = [[NSMutableArray alloc]init]; for (int i = 0; i< imgArry.count; i++) { GoodsBannerModel *model = [GoodsBannerModel xxx_loadWithModel:imgArry[i]]; if(i==0){ infoModel.add_gooodsImgUrl = model.small; } [modelAry addObject:model]; } self.dataAry = [NSMutableArray arrayWithArray:modelAry]; [self.BannerV reloadData]; [self.collectV reloadData]; } - (NSInteger)numberOfItemsInPagerView:(TYCyclePagerView *)pageView { return self.dataAry.count; } - (UICollectionViewCell *)pagerView:(TYCyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index{ GoodsBannerModel *model = self.dataAry[index]; if (model.cellType == CellContentTypeVideo) { GoodsVideoCollectionViewCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:GoodsVideoCollectionViewCellID forIndex:index]; cell.model = model; self.viedeoCell = cell; return cell; }else{ GoodsBannerCollectionViewCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:GoodsBannerCollectionViewCellID forIndex:index]; cell.model = self.dataAry[index]; return cell; } } - (TYCyclePagerViewLayout *)layoutForPagerView:(TYCyclePagerView *)pageView{ TYCyclePagerViewLayout *layout = [[TYCyclePagerViewLayout alloc]init]; layout.itemSize = CGSizeMake(KScreenWidth, KScreenWidth); layout.itemSpacing = 0; layout.layoutType = TYCyclePagerTransformLayoutNormal; layout.itemHorizontalCenter = YES; return layout; } #pragma mark - **************** TYCyclePagerViewDelegate **************** - (void)pagerView:(TYCyclePagerView *)pageView didSelectedItemCell:(__kindof UICollectionViewCell *)cell atIndex:(NSInteger)index { GoodsBannerModel *model = self.dataAry[index]; NSMutableArray *imgAry = [[NSMutableArray alloc]init]; for (GoodsBannerModel *tmpModel in self.dataAry) { if (tmpModel.cellType == CellContentTypeImg){ [imgAry addObject:tmpModel.url]; } } if (model.cellType == CellContentTypeImg) { [self tool_PhotosBroweserImages:imgAry index:index-(self.dataAry.count-imgAry.count)]; } } - (void)pagerView:(TYCyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex{ if(pageView.decelerating == YES){ [self.collectV selectItemAtIndexPath:[NSIndexPath indexPathForRow:toIndex inSection:0] animated:YES scrollPosition:UICollectionViewScrollPositionNone]; } } - (TYCyclePagerView *)BannerV { if (!_BannerV) { _BannerV = [[TYCyclePagerView alloc]init]; _BannerV.isInfiniteLoop = YES; _BannerV.dataSource = self; _BannerV.delegate = self; [_BannerV registerClass:[GoodsVideoCollectionViewCell class] forCellWithReuseIdentifier:GoodsVideoCollectionViewCellID]; [_BannerV registerClass:[GoodsBannerCollectionViewCell class] forCellWithReuseIdentifier:GoodsBannerCollectionViewCellID]; } return _BannerV; } -(NSMutableArray *)dataAry{ if (!_dataAry) { _dataAry = [[NSMutableArray alloc]init]; } return _dataAry; } - (void)xxx_dealloc{ if(self.viedeoCell){ [self.viedeoCell playerDealloc]; } } - (UICollectionView *)collectV { if (!_collectV) { UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; layout.sectionInset = UIEdgeInsetsMake(10, 0, 10, 0); layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; layout.itemSize = CGSizeMake(112, 112); UICollectionView *collV = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout]; collV.alwaysBounceHorizontal = true; collV.delegate = self; collV.dataSource = self; collV.showsHorizontalScrollIndicator = false; [collV registerClass:[SelectVCollectionViewCell class] forCellWithReuseIdentifier:SelectVCollectionViewCellID]; _collectV = collV; } return _collectV; } #pragma mark - **************** UICollectionViewDataSource **************** - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.dataAry.count; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { GoodsBannerModel *model = self.dataAry[indexPath.row]; SelectVCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:SelectVCollectionViewCellID forIndexPath:indexPath]; [cell.imgV sd_setImageWithURL:[NSURL URLWithString:model.small] placeholderImage:UIImageDefaultImg_SD]; return cell; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ [self.BannerV scrollToItemAtIndex:indexPath.row animate:YES]; [collectionView selectItemAtIndexPath:indexPath animated:YES scrollPosition:UICollectionViewScrollPositionNone]; } -(void)tool_PhotosBroweserImages:(NSMutableArray *)imageurlarr index:(NSInteger)index { NSMutableArray *photos = [[NSMutableArray alloc]init]; for (NSString *imgUrl in imageurlarr) { GKPhoto *photo = [GKPhoto new]; photo.placeholderImage = UIImageDefaultImg_SD; photo.url = [NSURL URLWithString:imgUrl]; [photos addObject:photo]; } GKPhotoBrowser *photoBrowser = [GKPhotoBrowser photoBrowserWithPhotos:photos currentIndex:index]; photoBrowser.showStyle = GKPhotoBrowserShowStyleNone; [photoBrowser showFromVC:[Current_normalTool topViewController]]; } @end