WKM_goodsBanner.m 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. } else {
  83. [imgAry addObject:tmpModel.small];
  84. }
  85. }
  86. if (model.cellType == CellContentTypeImg) {
  87. NSInteger atIndex = index - (self.dataAry.count-imgAry.count);
  88. if (atIndex <= 0) {
  89. atIndex = 0;
  90. }
  91. [self tool_PhotosBroweserImages:imgAry index:atIndex];
  92. }
  93. }
  94. - (void)pagerView:(TYCyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex{
  95. if(pageView.decelerating == YES){
  96. [self.collectV selectItemAtIndexPath:[NSIndexPath indexPathForRow:toIndex inSection:0] animated:YES scrollPosition:UICollectionViewScrollPositionNone];
  97. }
  98. }
  99. - (TYCyclePagerView *)BannerV {
  100. if (!_BannerV) {
  101. _BannerV = [[TYCyclePagerView alloc]init];
  102. _BannerV.isInfiniteLoop = NO;
  103. _BannerV.dataSource = self;
  104. _BannerV.delegate = self;
  105. [_BannerV registerClass:[GoodsVideoCollectionViewCell class] forCellWithReuseIdentifier:GoodsVideoCollectionViewCellID];
  106. [_BannerV registerClass:[GoodsBannerCollectionViewCell class] forCellWithReuseIdentifier:GoodsBannerCollectionViewCellID];
  107. }
  108. return _BannerV;
  109. }
  110. -(NSMutableArray *)dataAry{
  111. if (!_dataAry) {
  112. _dataAry = [[NSMutableArray alloc]init];
  113. }
  114. return _dataAry;
  115. }
  116. - (void)xxx_dealloc{
  117. if(self.viedeoCell){
  118. [self.viedeoCell playerDealloc];
  119. }
  120. }
  121. - (UICollectionView *)collectV {
  122. if (!_collectV) {
  123. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  124. layout.sectionInset = UIEdgeInsetsMake(10, 0, 10, 0);
  125. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  126. layout.itemSize = CGSizeMake(112, 112);
  127. UICollectionView *collV = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  128. collV.alwaysBounceHorizontal = true;
  129. collV.delegate = self;
  130. collV.dataSource = self;
  131. collV.showsHorizontalScrollIndicator = false;
  132. [collV registerClass:[SelectVCollectionViewCell class] forCellWithReuseIdentifier:SelectVCollectionViewCellID];
  133. _collectV = collV;
  134. }
  135. return _collectV;
  136. }
  137. #pragma mark - **************** UICollectionViewDataSource ****************
  138. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  139. return 1;
  140. }
  141. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  142. return self.dataAry.count;
  143. }
  144. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  145. GoodsBannerModel *model = self.dataAry[indexPath.row];
  146. SelectVCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:SelectVCollectionViewCellID forIndexPath:indexPath];
  147. [cell.imgV sd_setImageWithURL:[NSURL URLWithString:model.small] placeholderImage:UIImageDefaultImg_SD];
  148. return cell;
  149. }
  150. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  151. [self.BannerV scrollToItemAtIndex:indexPath.row animate:YES];
  152. [collectionView selectItemAtIndexPath:indexPath animated:YES scrollPosition:UICollectionViewScrollPositionNone];
  153. }
  154. -(void)tool_PhotosBroweserImages:(NSMutableArray *)imageurlarr index:(NSInteger)index {
  155. NSMutableArray *photos = [[NSMutableArray alloc]init];
  156. for (NSString *imgUrl in imageurlarr) {
  157. GKPhoto *photo = [GKPhoto new];
  158. photo.placeholderImage = UIImageDefaultImg_SD;
  159. photo.url = [NSURL URLWithString:imgUrl];
  160. [photos addObject:photo];
  161. }
  162. GKPhotoBrowser *photoBrowser = [GKPhotoBrowser photoBrowserWithPhotos:photos currentIndex:index];
  163. photoBrowser.showStyle = GKPhotoBrowserShowStyleNone;
  164. photoBrowser.failureText = @"Net Error";
  165. [photoBrowser showFromVC:[Current_normalTool topViewController]];
  166. }
  167. @end