123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- //
- // YOUPAIRightCollectionView.m
- // MSYOUPAI
- //
- // Created by xiaohaoran on 2022/3/1.
- // Copyright © 2022 MS. All rights reserved.
- //
- #import "YOUPAIRightCollectionView.h"
- #import "YOUPAIRightCollectionContentCell.h"
- #import "UIImage+Extension.h"
- @interface YOUPAIRightCollectionView ()<UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource>
- @property (nonatomic, strong) UICollectionView *youpaipcollectionView;
- @property (assign, nonatomic) NSIndexPath *selIndex; //单选选中的行
- @property(nonatomic,assign)BOOL isBigImage;//大图是否滚动
- @end
- @implementation YOUPAIRightCollectionView
- -(instancetype)initWithFrame:(CGRect)frame{
-
- if (self = [super initWithFrame:frame]) {
- [self youpaifsetSubView];
- }
- return self;
- }
- -(void)youpaifsetSubView{
-
- UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
- flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
- self.youpaipcollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
- [self addSubview:self.youpaipcollectionView];
- [self.youpaipcollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.mas_equalTo(0);
- }];
-
- // self.youpaipcollectionView.userInteractionEnabled = NO;
- self.youpaipcollectionView.backgroundColor = [UIColor clearColor];
- self.youpaipcollectionView.showsVerticalScrollIndicator = NO;
- self.youpaipcollectionView.showsHorizontalScrollIndicator = NO;
- // self.youpaipcollectionView.bounces = NO;
-
- [self.youpaipcollectionView registerClass:[YOUPAIRightCollectionContentCell class] forCellWithReuseIdentifier:NSStringFromClass([YOUPAIRightCollectionContentCell class])];
-
- self.youpaipcollectionView.delegate = self;
- self.youpaipcollectionView.dataSource = self;
-
- }
- #pragma mark <UICollectionViewDataSource>
- /**
- 返回区数
-
- @param collectionView 集合视图
- @return 返回区数
- */
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
- return 1;
- }
- /**
- 返回项目数
-
- @param collectionView 集合视图
- @param section 区
- @return 项目数
- */
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
-
-
- return self.Model.youpaipalbums.count;
- }
- -(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
- // NSString *imageUrl = self.albumArray[indexPath.item];
- YOUPAIRightCollectionContentCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([YOUPAIRightCollectionContentCell class]) forIndexPath:indexPath];
- YOUPAIAlbumModel *model = self.Model.youpaipalbums[indexPath.item];
-
- NSString *utlStr = [NSString stringWithFormat:@"%@/%@",[LCSaveData getImageUrl]?[LCSaveData getImageUrl]:BaseImgUrl,model.youpaipurl] ;
-
-
- [cell.youpaipiconImageView sd_setImageWithURL:[NSURL URLWithString:utlStr] placeholderImage:nil];
- if (indexPath.item ==0) {
- if (self.isBigImage) {
-
- cell.cycleShow = NO;
- }else{
- cell.cycleShow = YES;
- self.selIndex = [NSIndexPath indexPathForItem:0 inSection:0];
- }
- if (model.youpaipis_video ==1) {
- cell.youpaipplayImageView.hidden = NO;
- cell.youpaipiconImageView.image = [UIImage imageWithVideo:[NSURL URLWithString:utlStr]];
-
- }else{
- cell.youpaipplayImageView.hidden = YES;
- }
-
- }else{
- cell.youpaipplayImageView.hidden = YES;
- }
-
- return cell;
- }
- //+ (UIImage *)imageWithVideo:(NSURL *)videoURL
- //大图滚动后小图显示位置
- -(void)setScrollToItemAtIndex:(NSInteger)index{
- self.isBigImage = YES;
- [self.youpaipcollectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:index inSection:0] atScrollPosition:UICollectionViewScrollPositionTop animated:YES];
- YOUPAIRightCollectionContentCell *cell = (YOUPAIRightCollectionContentCell*)[self.youpaipcollectionView cellForItemAtIndexPath:self.selIndex];
- cell.cycleShow = NO;
- //记录当前的选择的位置
- _selIndex = [NSIndexPath indexPathForItem:index inSection:0];
- YOUPAIRightCollectionContentCell *cell1 = (YOUPAIRightCollectionContentCell*)[self.youpaipcollectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:index inSection:0]];
- cell1.cycleShow = YES;
- }
- -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
-
- YOUPAIRightCollectionContentCell *cell = (YOUPAIRightCollectionContentCell*)[self.youpaipcollectionView cellForItemAtIndexPath:self.selIndex];
- cell.cycleShow = NO;
- //记录当前的选择的位置
- _selIndex = indexPath;
- YOUPAIRightCollectionContentCell *cell1 = (YOUPAIRightCollectionContentCell*)[self.youpaipcollectionView cellForItemAtIndexPath:indexPath];
- cell1.cycleShow = YES;
-
- if (self.didSelectImageIndex) {
- self.didSelectImageIndex(indexPath.item);
- }
-
- }
- #pragma mark UICollectionViewDelegateFlowLayout
- /**
- 项目大小
-
- @param collectionView 集合视图
- @param collectionViewLayout 布局
- @param indexPath 布局
- @return 大小
- */
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
- return CGSizeMake(44, 44);
- }
- #pragma mark - X间距
- - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
- return 5.0;
- }
- //设置段落的内边距
- - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
- {
- return UIEdgeInsetsMake(0,0,0,0);//UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right)
- }
- @end
|