WKM_goodsBanner.m 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. //
  2. // WKM_goodsBanner.m
  3. // westkissMob
  4. //
  5. // Created by 王猛 on 2022/9/14.
  6. //
  7. #import "WKM_goodsBanner.h"
  8. #import "SelectVCollectionViewCell.h"
  9. #import <GKPhotoBrowser/GKPhotoBrowser.h>
  10. static NSString *const GoodsVideoCollectionViewCellID = @"GoodsVideoCollectionViewCellId";
  11. static NSString *const GoodsBannerCollectionViewCellID = @"GoodsBannerCollectionViewCellId";
  12. static NSString *const SelectVCollectionViewCellID = @"SelectVCollectionViewCellID";
  13. @interface WKM_goodsBanner()
  14. <TYCyclePagerViewDelegate,
  15. TYCyclePagerViewDataSource,
  16. UICollectionViewDataSource,
  17. UICollectionViewDelegate>
  18. @property (nonatomic, strong) NSMutableArray *dataAry;
  19. @property (nonatomic, strong) UICollectionView *collectV;
  20. @end
  21. @implementation WKM_goodsBanner
  22. - (void)tt_setupViews{
  23. [self addSubview:self.BannerV];
  24. [self addSubview:self.collectV];
  25. [self.BannerV mas_makeConstraints:^(MASConstraintMaker *make) {
  26. make.left.right.top.mas_equalTo(0);
  27. make.width.height.mas_equalTo(KScreenWidth);
  28. }];
  29. [self.collectV mas_makeConstraints:^(MASConstraintMaker *make) {
  30. make.left.mas_equalTo(10);
  31. make.right.mas_equalTo(0);
  32. make.top.equalTo(self.BannerV.mas_bottom).offset(10);
  33. make.height.mas_equalTo(112);
  34. }];
  35. }
  36. -(void)tt_confignewdata:(id)data{
  37. GoodsInformationM *infoModel = (GoodsInformationM *)data;
  38. NSMutableArray <MediaGalleryEntriesModel *>*imgArry =[NSMutableArray arrayWithArray:infoModel.media_gallery_entries];
  39. NSMutableArray *modelAry = [[NSMutableArray alloc]init];
  40. for (int i = 0; i< imgArry.count; i++) {
  41. GoodsBannerModel *model = [GoodsBannerModel xxx_loadWithModel:imgArry[i]];
  42. if(i==0){
  43. infoModel.add_gooodsImgUrl = model.small;
  44. }
  45. [modelAry addObject:model];
  46. }
  47. self.dataAry = [NSMutableArray arrayWithArray:modelAry];
  48. [self.BannerV reloadData];
  49. [self.collectV reloadData];
  50. }
  51. - (NSInteger)numberOfItemsInPagerView:(TYCyclePagerView *)pageView {
  52. return self.dataAry.count;
  53. }
  54. - (UICollectionViewCell *)pagerView:(TYCyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index{
  55. GoodsBannerModel *model = self.dataAry[index];
  56. if (model.cellType == CellContentTypeVideo) {
  57. GoodsVideoCollectionViewCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:GoodsVideoCollectionViewCellID forIndex:index];
  58. cell.model = model;
  59. self.viedeoCell = cell;
  60. return cell;
  61. }else{
  62. GoodsBannerCollectionViewCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:GoodsBannerCollectionViewCellID forIndex:index];
  63. cell.model = self.dataAry[index];
  64. return cell;
  65. }
  66. }
  67. - (TYCyclePagerViewLayout *)layoutForPagerView:(TYCyclePagerView *)pageView{
  68. TYCyclePagerViewLayout *layout = [[TYCyclePagerViewLayout alloc]init];
  69. layout.itemSize = CGSizeMake(KScreenWidth, KScreenWidth);
  70. layout.itemSpacing = 0;
  71. layout.layoutType = TYCyclePagerTransformLayoutNormal;
  72. layout.itemHorizontalCenter = YES;
  73. return layout;
  74. }
  75. #pragma mark - **************** TYCyclePagerViewDelegate ****************
  76. - (void)pagerView:(TYCyclePagerView *)pageView didSelectedItemCell:(__kindof UICollectionViewCell *)cell atIndex:(NSInteger)index {
  77. GoodsBannerModel *model = self.dataAry[index];
  78. NSMutableArray *imgAry = [[NSMutableArray alloc]init];
  79. for (GoodsBannerModel *tmpModel in self.dataAry) {
  80. if (tmpModel.cellType == CellContentTypeImg){
  81. [imgAry addObject:tmpModel.url];
  82. }
  83. }
  84. if (model.cellType == CellContentTypeImg) {
  85. [self tool_PhotosBroweserImages:imgAry index:index-(self.dataAry.count-imgAry.count)];
  86. }
  87. }
  88. - (void)pagerView:(TYCyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex{
  89. if(pageView.decelerating == YES){
  90. [self.collectV selectItemAtIndexPath:[NSIndexPath indexPathForRow:toIndex inSection:0] animated:YES scrollPosition:UICollectionViewScrollPositionNone];
  91. }
  92. }
  93. - (TYCyclePagerView *)BannerV {
  94. if (!_BannerV) {
  95. _BannerV = [[TYCyclePagerView alloc]init];
  96. _BannerV.isInfiniteLoop = YES;
  97. _BannerV.dataSource = self;
  98. _BannerV.delegate = self;
  99. [_BannerV registerClass:[GoodsVideoCollectionViewCell class] forCellWithReuseIdentifier:GoodsVideoCollectionViewCellID];
  100. [_BannerV registerClass:[GoodsBannerCollectionViewCell class] forCellWithReuseIdentifier:GoodsBannerCollectionViewCellID];
  101. }
  102. return _BannerV;
  103. }
  104. -(NSMutableArray *)dataAry{
  105. if (!_dataAry) {
  106. _dataAry = [[NSMutableArray alloc]init];
  107. }
  108. return _dataAry;
  109. }
  110. - (void)xxx_dealloc{
  111. if(self.viedeoCell){
  112. [self.viedeoCell playerDealloc];
  113. }
  114. }
  115. - (UICollectionView *)collectV {
  116. if (!_collectV) {
  117. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  118. layout.sectionInset = UIEdgeInsetsMake(10, 0, 10, 0);
  119. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  120. layout.itemSize = CGSizeMake(112, 112);
  121. UICollectionView *collV = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  122. collV.alwaysBounceHorizontal = true;
  123. collV.delegate = self;
  124. collV.dataSource = self;
  125. collV.showsHorizontalScrollIndicator = false;
  126. [collV registerClass:[SelectVCollectionViewCell class] forCellWithReuseIdentifier:SelectVCollectionViewCellID];
  127. _collectV = collV;
  128. }
  129. return _collectV;
  130. }
  131. #pragma mark - **************** UICollectionViewDataSource ****************
  132. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  133. return 1;
  134. }
  135. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  136. return self.dataAry.count;
  137. }
  138. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  139. GoodsBannerModel *model = self.dataAry[indexPath.row];
  140. SelectVCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:SelectVCollectionViewCellID forIndexPath:indexPath];
  141. [cell.imgV sd_setImageWithURL:[NSURL URLWithString:model.small] placeholderImage:UIImageDefaultImg_SD];
  142. return cell;
  143. }
  144. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  145. [self.BannerV scrollToItemAtIndex:indexPath.row animate:YES];
  146. [collectionView selectItemAtIndexPath:indexPath animated:YES scrollPosition:UICollectionViewScrollPositionNone];
  147. }
  148. -(void)tool_PhotosBroweserImages:(NSMutableArray *)imageurlarr index:(NSInteger)index {
  149. NSMutableArray *photos = [[NSMutableArray alloc]init];
  150. for (NSString *imgUrl in imageurlarr) {
  151. GKPhoto *photo = [GKPhoto new];
  152. photo.placeholderImage = UIImageDefaultImg_SD;
  153. photo.url = [NSURL URLWithString:imgUrl];
  154. [photos addObject:photo];
  155. }
  156. GKPhotoBrowser *photoBrowser = [GKPhotoBrowser photoBrowserWithPhotos:photos currentIndex:index];
  157. photoBrowser.showStyle = GKPhotoBrowserShowStyleNone;
  158. [photoBrowser showFromVC:[Current_normalTool topViewController]];
  159. }
  160. @end