android ios 相册图片多选,IOS多选单选相册图片

#import "ViewController.h"

#import

#import "AppDelegate.h"

#import "PhoModel.h"

#import "PhoCollectionViewCell.h"

#define ApplicationDelegate ((AppDelegate *)[UIApplication sharedApplication].delegate)

static NSInteger count = 0;@interfaceViewController ()

{

NSMutableArray*mutableAssets;

}

@property (weak, nonatomic) IBOutlet UICollectionView*collectionView;@end

@implementationViewController- (void)viewDidLoad {

[super viewDidLoad];//获取相册中的全部照片

[self getAllPictures];

[_collectionView registerNib: [UINib nibWithNibName:@"PhoCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"CollectionViewCell"];

}//获取相册中的全部照片

-(void)getAllPictures {

mutableAssets=[[NSMutableArray alloc]init];

NSMutableArray*assetURLDictionaries =[[NSMutableArray alloc] init];

NSMutableArray*assetGroups =[[NSMutableArray alloc] init];

__block NSMutableArray*tempMutableAssets =mutableAssets;

__block ViewController*tempSelf =self;

__block NSMutableArray*tempAssetGroups =assetGroups;

[ApplicationDelegate.library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop){if (group !=nil) {

count=[group numberOfAssets];

__blockint groupNum = 0;

[group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop){if(asset !=nil) {++groupNum;if([[asset valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto]) {

[assetURLDictionaries addObject:[asset valueForProperty:ALAssetPropertyURLs]];

NSURL*url= (NSURL*) [[asset defaultRepresentation]url];

NSLog(@"%@,%@",[asset valueForProperty:ALAssetPropertyDate],url);//[UIImage imageWithCGImage:[[result defaultRepresentation] fullScreenImage]];//图片//[UIImage imageWithCGImage:[result thumbnail]];//缩略图

PhoModel*phoModel=[[PhoModel alloc]init];

phoModel.asset=asset;

phoModel.isSelected=NO;

[tempMutableAssets addObject:phoModel];if (tempMutableAssets.count ==groupNum) {

[tempSelf allPhotosCollected:tempMutableAssets];

}

}

}

}];

[tempAssetGroups addObject:group];

}

}failureBlock:^(NSError *error){

NSLog(@"There is an error");

}];

}//所有asset

-(void)allPhotosCollected:(NSMutableArray *)mutableAsset{

[self.collectionView reloadData];

}#pragma mark -- UICollectionViewDataSource

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {

CGSize itemSize= CGSizeMake(([UIScreen mainScreen].bounds.size.width-15)/4.0, ([UIScreen mainScreen].bounds.size.width-30)/4.0);returnitemSize;

}//定义展示的UICollectionViewCell的个数

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section

{return mutableAssets.count+1;

}//每个UICollectionView展示的内容

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath

{static NSString * CellIdentifier = @"CollectionViewCell";

PhoCollectionViewCell* cell =[collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];if (indexPath.row==0) {

cell.imageView.image= [UIImage imageNamed:@"0.png"];

cell.selectImageView.hidden=YES;

cell.selectBtnClickBlock=^(BOOL isSelect)

{

NSLog(@"cell1 block");

};returncell;

}

PhoModel*phoModel = mutableAssets[indexPath.row-1];

cell.imageView.image=[UIImage imageWithCGImage:[phoModel.asset thumbnail]];if(phoModel.isSelected) {

cell.selectImageView.image=[UIImage imageNamed:@"2.png"];

}else{

cell.selectImageView.image=[UIImage imageNamed:@"1.png"];

}

cell.selectImageView.hidden=NO;

cell.selectBtn.selected=phoModel.isSelected;

cell.selectBtnClickBlock=^(BOOL isSelect)

{//单选多选标记 false 单选 true 多选

BOOL issangal=false;if(issangal) {for (PhoModel *tmpPhotoModel inmutableAssets) {

tmpPhotoModel.isSelected=NO;

}

}

phoModel.isSelected=isSelect;

[_collectionView reloadData];

};returncell;

}- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {

NSLog(@"%ld",indexPath.row);

}- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];//Dispose of any resources that can be recreated.

}@end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值