| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 |
- //
- // ImageAttachmentCell.m
- // IBOSS
- //
- // Created by 关宏厚 on 2020/7/27.
- // Copyright © 2020 elongtian. All rights reserved.
- //
- #import "ImageAttachmentCell.h"
- #import "AlbumPhotoCollectionViewCell.h"
- #import "XHAlbumCollectionViewFlowLayout.h"
- #import "XHImageViewer.h"
- #import "ImageModel.h"
- #define PhotoCollectionViewCellIdentifier @"PhotoCollectionViewCellIdentifier"
- @interface AttachmentPhotoCollectionView : UICollectionView
- @end
- @implementation AttachmentPhotoCollectionView
- @end
- @interface ImageAttachmentCell(){
- // 底部灰背景
- UIView *_viewBottomBackgroud;
- // UIControl控件
- UIControl *_control;
- }
- /**
- 图片控件
- */
- @property (nonatomic, strong) AttachmentPhotoCollectionView *photoCollectionView;
- @end
- @implementation ImageAttachmentCell
- @synthesize subView;
- /**
- 初始化
-
- @param style <#style description#>
- @param reuseIdentifier <#reuseIdentifier description#>
- @return <#return value description#>
- */
- - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
- {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- // Initialization code
- [self initUI];
- }
- return self;
- }
- /**
- 初始化ui
- */
- - (void)initUI
- {
- _control = [[UIControl alloc] initWithFrame:CGRectMake(0, 0,Screen_Width,40)];
- [_control addTarget:self action:@selector(headerClick:) forControlEvents:UIControlEventTouchUpInside];
- [self.contentView addSubview:_control];
-
- _imgInfoTitle = [[UILabel alloc] init];
- _imgInfoTitle.frame=CGRectMake(20,7,120,25);
- _imgInfoTitle.text = @"方案附件信息";
- _imgInfoTitle.backgroundColor = [UIColor clearColor];
- _imgInfoTitle.font = [UIFont systemFontOfSize:14.0f];
- _imgInfoTitle.textColor = [UIColor redColor];
- [self.contentView addSubview:_imgInfoTitle];
-
- _btnArrow = [UIButton buttonWithType:UIButtonTypeCustom];
- _btnArrow.frame=CGRectMake(Screen_Width-30,12,16, 16);
- [_btnArrow setBackgroundImage:[UIImage imageNamed:@"arrow-down"] forState: UIControlStateNormal];
- [_btnArrow addTarget:self action:@selector(headerClick:) forControlEvents:UIControlEventTouchUpInside];
- [self.contentView addSubview:_btnArrow];
- }
- /**
- 图片
-
- @param infoDetail <#infoDetail description#>
- */
- - (void)setImageInfo:(CustomerInfoDetailModel *)infoDetail {
-
- _infoDetailModel=infoDetail;
- NSMutableArray *imgArr;
- subView = [[UIView alloc]init];
- [self.contentView addSubview:subView];
- subView.backgroundColor = [UIColor clearColor];
- CGRect photoFrame;
-
- imgArr = [_infoDetailModel imageAttachmentDisplayArr];
- if(imgArr != nil&&[imgArr count]>0){
- photoFrame= [infoDetail getPhotoFrame:[infoDetail imageAttachmentDisplayArr ]];
-
- subView.frame=CGRectMake(0,CGRectGetMaxY(_control.frame), Screen_Width, [infoDetail getPhotoCollectionViewHeightWithPhotos:[infoDetail imageAttachmentDisplayArr ]]);
-
- //分割线
- UIView *_viewBackgroud = [UIView new];
- _viewBackgroud.frame = CGRectMake(0, 0, Screen_Width, 1);
- _viewBackgroud.backgroundColor = LineBackgroundColor;
- [subView addSubview:_viewBackgroud];
-
- _photoCollectionView = [[AttachmentPhotoCollectionView alloc] initWithFrame:photoFrame collectionViewLayout:[[XHAlbumCollectionViewFlowLayout alloc] init]];
- _photoCollectionView.backgroundColor = [UIColor clearColor];
- [_photoCollectionView registerClass:[AlbumPhotoCollectionViewCell class] forCellWithReuseIdentifier:PhotoCollectionViewCellIdentifier];
- _photoCollectionView.delegate = self;
- _photoCollectionView.scrollEnabled=NO;
- _photoCollectionView.dataSource = self;
- [subView addSubview:self.photoCollectionView];
- [self.photoCollectionView reloadData];
- }
-
- else
- {
- subView.frame=CGRectMake(0,CGRectGetMaxY(_control.frame), Screen_Width, 0);
- }
-
- _viewBottomBackgroud = [UIView new];
- _viewBottomBackgroud.backgroundColor = LineBackgroundColor;
- [self.contentView addSubview:_viewBottomBackgroud];
- if([_isOpen isEqualToString:@"1"])
- {
- subView.hidden=NO;
- _viewBottomBackgroud.frame = CGRectMake(0, CGRectGetMaxY(subView.frame), Screen_Width, 10);
- }
- else
- {
- subView.hidden=YES;
- _viewBottomBackgroud.frame = CGRectMake(0, CGRectGetMaxY(_control.frame), Screen_Width, 10);
- }
- }
- /**
- 图片个数
-
- @param collectionView <#collectionView description#>
- @param section <#section description#>
- @return <#return value description#>
- */
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- return [[_infoDetailModel imageAttachmentDisplayArr ] count];
- }
- /**
- 单元格图片
-
- @param collectionView <#collectionView description#>
- @param indexPath <#indexPath description#>
- @return <#return value description#>
- */
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
- AlbumPhotoCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:PhotoCollectionViewCellIdentifier forIndexPath:indexPath];
-
- cell.indexPath = indexPath;
- ImageModel *image = [[_infoDetailModel imageAttachmentDisplayArr ] objectAtIndex:indexPath.row];
- NSString *imagepath = [image imageName];
- if(imagepath != nil&&[imagepath length]>0){
- NSString *imageUrl = [NSString stringWithFormat:@"http://%@:%@/WebService/%@",kkServerUrl,kkServerPort,imagepath];
- NSURL *url = [NSURL URLWithString:imageUrl];
- [cell.photoImageView downloadImageWithURL:url];
- }
- return cell;
- }
- /**
- 点击事件
-
- @param sender <#sender description#>
- */
- - (void)headerClick:(id)sender{
- [self rotateArrowImage];
- if([self.delegate respondsToSelector:@selector(refreshTableView)])
- {
- [self.delegate performSelector:@selector(refreshTableView) withObject:nil afterDelay:0.0 ];
- }
- }
- /**
- 图片高度
-
- @param photos <#photos description#>
- @return <#return value description#>
- */
- + (CGFloat)getPhotoCollectionViewHeightWithPhotos:(NSArray *)photos {
- // 上下间隔已经在frame上做了
- NSInteger row = (photos.count / 3 + (photos.count % 3 ? 1 : 0));
- return (row *85 + ((row - 1) *5));
- }
- /**
- 展开,收缩
- */
- - (void)rotateArrowImage{
- //如果已经展开,收缩
- if([_isOpen isEqualToString:@"1"]){
- [UIView animateWithDuration:0.2 animations:^{
- self.btnArrow.transform = CGAffineTransformMakeRotation(0 / 180.0 * M_PI );
- }];
- _isOpen = @"0";
- subView.hidden=YES;
- _viewBottomBackgroud.frame = CGRectMake(0, CGRectGetMaxY(_control.frame), Screen_Width, 10);
- }else{
- [UIView animateWithDuration:0.2 animations:^{
- self.btnArrow.transform = CGAffineTransformMakeRotation(180 / 180.0 * M_PI );
- }];
- _isOpen = @"1";
- subView.hidden=NO;
- _viewBottomBackgroud.frame = CGRectMake(0, CGRectGetMaxY(subView.frame), Screen_Width, 10);
- }
- }
- /**
- 是否展开,收缩
-
- @param aIsOpen <#aIsOpen description#>
- */
- - (void)setIsOpen:(NSString *)aIsOpen{
- _isOpen = aIsOpen;
- if([_isOpen isEqualToString:@"1"]){
- self.btnArrow.transform = CGAffineTransformMakeRotation(180 / 180.0 * M_PI );
- subView.hidden=NO;
- _viewBottomBackgroud.frame = CGRectMake(0, CGRectGetMaxY(subView.frame), Screen_Width, 10);
- }
- else
- {
- self.btnArrow.transform = CGAffineTransformMakeRotation(0 / 180.0 * M_PI );
- subView.hidden=YES;
- _viewBottomBackgroud.frame = CGRectMake(0, CGRectGetMaxY(_control.frame), Screen_Width, 10);
- }
- }
- #pragma mark - UICollectionView Delegate
- /**
- 选择图片
-
- @param collectionView <#collectionView description#>
- @param indexPath <#indexPath description#>
- */
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
-
- [self showImageViewerAtIndexPath:indexPath];
- }
- /**
- 选择图片
-
- @param indexPath <#indexPath description#>
- */
- - (void)showImageViewerAtIndexPath:(NSIndexPath *)indexPath {
- AlbumPhotoCollectionViewCell *cell = (AlbumPhotoCollectionViewCell *)[self.photoCollectionView cellForItemAtIndexPath:indexPath];
-
- NSMutableArray *imageViews = [NSMutableArray array];
- NSArray *visibleCell = [self.photoCollectionView visibleCells];
-
- NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"indexPath" ascending:YES];
-
- visibleCell = [visibleCell sortedArrayUsingDescriptors:[NSArray arrayWithObject:sort]];
-
- [visibleCell enumerateObjectsUsingBlock:^(AlbumPhotoCollectionViewCell *cell, NSUInteger idx, BOOL *stop) {
- [imageViews addObject:[[cell.contentView subviews] lastObject]];
- }];
-
- XHImageViewer *imageViewer = [[XHImageViewer alloc] init];
- [imageViewer showWithImageViews:imageViews selectedView:[[cell.contentView subviews] lastObject]];
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- @end
|