// // PBCommentsFooterView.m // IphoneBIMe // // Created by zjf on 2018/9/4. // Copyright © 2018年 ProBIM. All rights reserved. // #import "PBCommentsFooterView.h" #import "PBImageCollectionViewCell.h" #define ALineCount 3 #define Spacing 10 static NSString *const cellID = @"cellID"; @interface PBCommentsFooterView() @property (nonatomic, strong) UICollectionView *collectionView; @property (nonatomic, assign) CGFloat itemWH; @end @implementation PBCommentsFooterView - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { [self setupUI]; } return self; } - (void)setupUI { self.backgroundColor = [UIColor whiteColor]; [self addSubview:self.collectionView]; self.collectionView.backgroundColor = [UIColor whiteColor]; [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self).offset(16); make.left.equalTo(self).offset(Spacing); make.right.equalTo(self).offset(-Spacing); make.bottom.equalTo(self).offset(-16); }]; } - (UICollectionView *)collectionView{ if (!_collectionView) { UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout.alloc init]; CGFloat itemWH = (PBScreenWidth - (ALineCount + 1) * Spacing) / ALineCount; self.itemWH = itemWH; layout.itemSize = CGSizeMake(itemWH, itemWH); layout.minimumLineSpacing = Spacing; layout.minimumInteritemSpacing = Spacing; layout.scrollDirection = UICollectionViewScrollDirectionVertical; _collectionView = [UICollectionView.alloc initWithFrame:CGRectZero collectionViewLayout:layout]; _collectionView.backgroundColor = [UIColor whiteColor]; [_collectionView registerClass:[PBImageCollectionViewCell class] forCellWithReuseIdentifier:cellID]; _collectionView.delegate = self; _collectionView.dataSource = self; } return _collectionView; } #pragma mark - UICollectionViewDataSource - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ return self.selectedPhotos.count; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ PBImageCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath]; cell.image = self.selectedPhotos[indexPath.row]; cell.roleType = CREATOR; cell.DeleteImageBlock = ^{ if (self.deleteImageBlock) { self.deleteImageBlock(indexPath.row); } }; return cell; } #pragma mark - UICollectionViewDelegate - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { SDPhotoBrowser *photoBrowser = [SDPhotoBrowser new]; photoBrowser.delegate = self; photoBrowser.currentImageIndex = indexPath.item; photoBrowser.imageCount = self.selectedPhotos.count; photoBrowser.sourceImagesContainerView = self.collectionView; [photoBrowser show]; } #pragma mark - SDPhotoBrowserDelegate // 返回临时占位图片(即原来的小图) - (UIImage *)photoBrowser:(SDPhotoBrowser *)browser placeholderImageForIndex:(NSInteger)index { // 不建议用此种方式获取小图,这里只是为了简单实现展示而已 PBImageCollectionViewCell *cell = (PBImageCollectionViewCell *)[self collectionView:self.collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:index inSection:0]]; return cell.imageV.image; } - (void)setSelectedPhotos:(NSMutableArray *)selectedPhotos { _selectedPhotos = selectedPhotos; [self.collectionView reloadData]; } @end