zjf
2023-03-06 392b76515f40376b6d36f40a114850ef63650384
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//
//  PBScheduleImgTableViewCell.m
//  IphoneBIMe
//
//  Created by ZhangJF on 2022/9/9.
//  Copyright © 2022 ProBIM. All rights reserved.
//
 
#import "PBScheduleImgTableViewCell.h"
#import "PBImgAndNameCollectionViewCell.h"
#import "PBImageModel.h"
 
static NSString *const cellID = @"cellID";
@interface PBScheduleImgTableViewCell()<UICollectionViewDelegate, UICollectionViewDataSource, SDPhotoBrowserDelegate>
@property (nonatomic, weak) UICollectionView *collectionView; //图片
@end
@implementation PBScheduleImgTableViewCell
 
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}
- (void)setupUI {
    UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout.alloc init];
    layout.itemSize = CGSizeMake(168, 140);
    layout.minimumLineSpacing = 10;
    layout.minimumInteritemSpacing = 0;
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    UICollectionView *collectionView = [UICollectionView.alloc initWithFrame:CGRectZero collectionViewLayout:layout];
    [collectionView registerClass:[PBImgAndNameCollectionViewCell class] forCellWithReuseIdentifier:cellID];
    collectionView.delegate = self;
    collectionView.dataSource = self;
    collectionView.pagingEnabled = YES;
//        _collectionView.bounces = NO;
    collectionView.showsHorizontalScrollIndicator = NO;
    collectionView.backgroundColor = [UIColor whiteColor];
//    collectionView.contentInset = UIEdgeInsetsMake(0, 0, 0, 100);
    [self.contentView addSubview:collectionView];
    [collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView);
        make.left.equalTo(self.contentView).offset(12);
        make.right.equalTo(self.contentView).offset(-12);
        make.bottom.equalTo(self.contentView);
        make.height.mas_equalTo(@140);
    }];
    self.collectionView = collectionView;
}
 
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.imageArr.count;
}
 
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    PBImgAndNameCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
    PBImageModel *model = self.imageArr[indexPath.row];
    cell.model = model;
    cell.DeleteImageBlock = ^{
        if (model.bf_path) {
            if (self.DeleteImageBlock){
                self.DeleteImageBlock(indexPath.item);
            }
        }else {
            [self.imageArr removeObjectAtIndex:indexPath.row];
            [self.collectionView reloadData];
        }
    };
    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    SDPhotoBrowser *photoBrowser = [SDPhotoBrowser new];
    photoBrowser.delegate = self;
    photoBrowser.currentImageIndex = indexPath.item;
    photoBrowser.imageCount = self.imageArr.count;
//        photoBrowser.sourceImagesContainerView = self.collectionView;
    [photoBrowser show];
}
 
#pragma mark  SDPhotoBrowserDelegate
// 返回临时占位图片(即原来的小图)
- (UIImage *)photoBrowser:(SDPhotoBrowser *)browser placeholderImageForIndex:(NSInteger)index {
    // 不建议用此种方式获取小图,这里只是为了简单实现展示而已
    PBImgAndNameCollectionViewCell *cell = (PBImgAndNameCollectionViewCell *)[self collectionView:self.collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:index inSection:0]];
//    if (self.isAddExamine) {
        return cell.imageV.image;
//    }else {
//        NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:cell.imageUrl]];
//        UIImage *image = [UIImage imageWithData:data];;
//        return image;
//    }
}
- (void)setImageArr:(NSMutableArray *)imageArr {
    _imageArr = imageArr;
    [self.collectionView reloadData];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
 
    // Configure the view for the selected state
}
 
@end