WKM_goodsBanner.m 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 *model = (GoodsInformationM *)data;
  38. NSMutableArray *imgArry =[NSMutableArray arrayWithArray:model.imgarr];
  39. NSMutableArray *modelAry = [[NSMutableArray alloc]init];
  40. for (int i = 0; i< imgArry.count; i++) {
  41. GoodsBannerModel *model = [GoodsBannerModel xxx_loadWithModel:imgArry[i]];
  42. [modelAry addObject:model];
  43. }
  44. self.dataAry = [NSMutableArray arrayWithArray:modelAry];
  45. [self.BannerV reloadData];
  46. [self.collectV reloadData];
  47. }
  48. - (NSInteger)numberOfItemsInPagerView:(TYCyclePagerView *)pageView {
  49. return self.dataAry.count;
  50. }
  51. - (UICollectionViewCell *)pagerView:(TYCyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index{
  52. GoodsBannerModel *model = self.dataAry[index];
  53. if (model.cellType == CellContentTypeVideo) {
  54. GoodsVideoCollectionViewCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:GoodsVideoCollectionViewCellID forIndex:index];
  55. cell.model = model;
  56. self.viedeoCell = cell;
  57. return cell;
  58. }else{
  59. GoodsBannerCollectionViewCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:GoodsBannerCollectionViewCellID forIndex:index];
  60. cell.model = self.dataAry[index];
  61. return cell;
  62. }
  63. }
  64. - (TYCyclePagerViewLayout *)layoutForPagerView:(TYCyclePagerView *)pageView{
  65. TYCyclePagerViewLayout *layout = [[TYCyclePagerViewLayout alloc]init];
  66. layout.itemSize = CGSizeMake(KScreenWidth, KScreenWidth);
  67. layout.itemSpacing = 0;
  68. layout.layoutType = TYCyclePagerTransformLayoutNormal;
  69. layout.itemHorizontalCenter = YES;
  70. return layout;
  71. }
  72. #pragma mark - **************** TYCyclePagerViewDelegate ****************
  73. - (void)pagerView:(TYCyclePagerView *)pageView didSelectedItemCell:(__kindof UICollectionViewCell *)cell atIndex:(NSInteger)index {
  74. GoodsBannerModel *model = self.dataAry[index];
  75. NSMutableArray *imgAry = [[NSMutableArray alloc]init];
  76. for (GoodsBannerModel *tmpModel in self.dataAry) {
  77. if (tmpModel.cellType == CellContentTypeImg){
  78. [imgAry addObject:tmpModel.url];
  79. }
  80. }
  81. if (model.cellType == CellContentTypeImg) {
  82. [self tool_PhotosBroweserImages:imgAry index:index-(self.dataAry.count-imgAry.count)];
  83. }
  84. }
  85. - (void)pagerView:(TYCyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex{
  86. if(pageView.decelerating == YES){
  87. [self.collectV selectItemAtIndexPath:[NSIndexPath indexPathForRow:toIndex inSection:0] animated:YES scrollPosition:UICollectionViewScrollPositionNone];
  88. }
  89. }
  90. - (TYCyclePagerView *)BannerV {
  91. if (!_BannerV) {
  92. _BannerV = [[TYCyclePagerView alloc]init];
  93. _BannerV.isInfiniteLoop = YES;
  94. _BannerV.dataSource = self;
  95. _BannerV.delegate = self;
  96. [_BannerV registerClass:[GoodsVideoCollectionViewCell class] forCellWithReuseIdentifier:GoodsVideoCollectionViewCellID];
  97. [_BannerV registerClass:[GoodsBannerCollectionViewCell class] forCellWithReuseIdentifier:GoodsBannerCollectionViewCellID];
  98. }
  99. return _BannerV;
  100. }
  101. -(NSMutableArray *)dataAry{
  102. if (!_dataAry) {
  103. _dataAry = [[NSMutableArray alloc]init];
  104. }
  105. return _dataAry;
  106. }
  107. - (void)xxx_dealloc{
  108. if(self.viedeoCell){
  109. [self.viedeoCell playerDealloc];
  110. }
  111. }
  112. - (UICollectionView *)collectV {
  113. if (!_collectV) {
  114. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  115. layout.sectionInset = UIEdgeInsetsMake(10, 0, 10, 0);
  116. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  117. layout.itemSize = CGSizeMake(112, 112);
  118. UICollectionView *collV = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  119. collV.alwaysBounceHorizontal = true;
  120. collV.delegate = self;
  121. collV.dataSource = self;
  122. collV.showsHorizontalScrollIndicator = false;
  123. [collV registerClass:[SelectVCollectionViewCell class] forCellWithReuseIdentifier:SelectVCollectionViewCellID];
  124. _collectV = collV;
  125. }
  126. return _collectV;
  127. }
  128. #pragma mark - **************** UICollectionViewDataSource ****************
  129. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  130. return 1;
  131. }
  132. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  133. return self.dataAry.count;
  134. }
  135. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  136. GoodsBannerModel *model = self.dataAry[indexPath.row];
  137. SelectVCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:SelectVCollectionViewCellID forIndexPath:indexPath];
  138. [cell.imgV sd_setImageWithURL:[NSURL URLWithString:model.url] placeholderImage:UIImageDefaultImg_SD];
  139. return cell;
  140. }
  141. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  142. [self.BannerV scrollToItemAtIndex:indexPath.row animate:YES];
  143. [collectionView selectItemAtIndexPath:indexPath animated:YES scrollPosition:UICollectionViewScrollPositionNone];
  144. }
  145. -(void)tool_PhotosBroweserImages:(NSMutableArray *)imageurlarr index:(NSInteger)index {
  146. NSMutableArray *photos = [[NSMutableArray alloc]init];
  147. for (NSString *imgUrl in imageurlarr) {
  148. GKPhoto *photo = [GKPhoto new];
  149. photo.placeholderImage = UIImageDefaultImg_SD;
  150. photo.url = [NSURL URLWithString:imgUrl];
  151. [photos addObject:photo];
  152. }
  153. GKPhotoBrowser *photoBrowser = [GKPhotoBrowser photoBrowserWithPhotos:photos currentIndex:index];
  154. photoBrowser.showStyle = GKPhotoBrowserShowStyleNone;
  155. [photoBrowser showFromVC:[Current_normalTool topViewController]];
  156. }
  157. @end