GiGaMaskTime/GIGA/Modules/Me/View/FeedViews/GIGaFeedPhontosViewCell.m

188 lines
6.0 KiB
Objective-C

//
// GIGaFeedPhontosViewCell.m
// GIGA
//
// Created by lianxiang on 2018/9/22.
// Copyright © 2018年 com.giga.ios. All rights reserved.
//
#import "GIGaFeedPhontosViewCell.h"
#import "GIGaFeedImagsCollectionCell.h"
#import "GiGaFeedImagsActionCell.h"
#import "SJPhotoPickerManager.h"
#import "SJPhotoPicker.h"
#import "GIGaUserFileHelper.h"
@interface GIGaFeedPhontosViewCell()<UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>
@end
@implementation GIGaFeedPhontosViewCell
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.selectionStyle = UITableViewCellSelectionStyleNone;
_images = [NSMutableArray new];
[self creatUI];
}
return self;
}
- (NSMutableArray *)imageNames{
if (!_imageNames) {
_imageNames = [NSMutableArray new];
}
return _imageNames;
}
-(void)creatUI{
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
flowLayout.minimumLineSpacing = 1;
flowLayout.minimumInteritemSpacing = .1;
CGFloat width = (KMainW-15*2 - 22*2)/3;
flowLayout.itemSize = CGSizeMake(width,width);
//展示两行
//CGFloat HCELL= (itemH*1+1)*2;
_collectionView=[[UICollectionView alloc]initWithFrame:CGRectMake(0,0,KMainW, 218) collectionViewLayout:flowLayout];
_collectionView.delegate=self;
_collectionView.dataSource=self;
_collectionView.bounces=NO;
_collectionView.scrollEnabled=NO;
_collectionView.showsVerticalScrollIndicator=NO;
_collectionView.backgroundColor = GIGA_MAIN_BGCOLOR;
[self addSubview:_collectionView];
[_collectionView registerNib:[UINib nibWithNibName:@"GiGaFeedImagsActionCell" bundle:nil] forCellWithReuseIdentifier:@"GiGaFeedImagsActionCell"];
[_collectionView registerNib:[UINib nibWithNibName:@"GIGaFeedImagsCollectionCell" bundle:nil] forCellWithReuseIdentifier:@"GIGaFeedImagsCollectionCell"];
}
#pragma mark <UICollectionViewDataSource>
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 1 + self.images.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == self.images.count) {
GiGaFeedImagsActionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"GiGaFeedImagsActionCell" forIndexPath:indexPath];
if (!cell) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"GiGaFeedImagsActionCell" owner:self options:nil] lastObject];
}
[cell.imageAdd addTarget:self action:@selector(addBtnAction:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
GIGaFeedImagsCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"GIGaFeedImagsCollectionCell" forIndexPath:indexPath];
if (!cell) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"GIGaFeedImagsCollectionCell" owner:self options:nil] lastObject];
}
cell.delecBtn.tag = indexPath.row;
[cell.delecBtn addTarget:self action:@selector(delecBtnAction:) forControlEvents:UIControlEventTouchUpInside];
//PHImageManagerMaximumSize
[self.imageNames removeAllObjects];
[[SJPhotoPickerManager shareSJPhotoPickerManager] requestImageForPHAsset:self.images[indexPath.row] targetSize:CGSizeMake(200, 200) imageResult:^(UIImage *image) {
cell.uploadImageView.image = image;
if (image) {
cell.holdImageView.hidden = YES;
}else{
cell.holdImageView.hidden = NO;
}
cell.holdView.backgroundColor = [UIColor clearColor];
NSString *name = [NSString stringWithFormat:@"gigafeed_index%ld",(long)indexPath.row];
[GIGaUserFileHelper saveUserFeedbackImag:name image:image];
if ([self.imageNames containsObject: name]) {
[self.imageNames removeObject:name];
}
[self.imageNames addObject:name];
}];
return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat width = (KMainW-15*2 - 22*2)/3;
CGSize itemSize = CGSizeMake(width,width);
return itemSize;
}
//距离上下左右的间距
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
return UIEdgeInsetsMake(0,15,0, 15);
}
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
//设置最小的列间
return 22.0f;
}
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
//设置最小的行间距
return 10.0f;
}
-(void)delecBtnAction:(UIButton *)btn{
GILog(@"删除");
NSUInteger index = btn.tag;
[self.images removeObjectAtIndex:index];
[GIGaUserFileHelper delectAllfeedimages];
[self.imageNames removeAllObjects];
[self.collectionView reloadData];
}
-(void)addBtnAction:(UIButton*)btn{
if (self.pickerBalock){
self.pickerBalock();
}
}
- (void)photoPikerComplete:(GiGaPhotoPickerBlock)pikerComplete{
if (self.pickerBalock) {
self.pickerBalock = pikerComplete;
}
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end