123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- //
- // WKM_goodsBanner.m
- // westkissMob
- //
- // Created by 王猛 on 2022/9/14.
- //
- #import "WKM_goodsBanner.h"
- #import "SelectVCollectionViewCell.h"
- #import <GKPhotoBrowser/GKPhotoBrowser.h>
- static NSString *const GoodsVideoCollectionViewCellID = @"GoodsVideoCollectionViewCellId";
- static NSString *const GoodsBannerCollectionViewCellID = @"GoodsBannerCollectionViewCellId";
- static NSString *const SelectVCollectionViewCellID = @"SelectVCollectionViewCellID";
- @interface WKM_goodsBanner()
- <TYCyclePagerViewDelegate,
- TYCyclePagerViewDataSource,
- UICollectionViewDataSource,
- UICollectionViewDelegate>
- @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 <MediaGalleryEntriesModel *>*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];
- } else {
- [imgAry addObject:tmpModel.small];
- }
- }
- if (model.cellType == CellContentTypeImg) {
-
- NSInteger atIndex = index - (self.dataAry.count-imgAry.count);
- if (atIndex <= 0) {
- atIndex = 0;
- }
- [self tool_PhotosBroweserImages:imgAry index:atIndex];
- }
- }
- - (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 = NO;
- _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.failureText = @"Net Error";
- [photoBrowser showFromVC:[Current_normalTool topViewController]];
- }
- @end
|