自定义多选相册
主要思路
- 导入AssetsLibrary框架
- 从资源库中获取获取资源组【0】,过滤【1】照片后在列表中显示组。
- 点击资源组进入对应的相册中,获取组中的所有照片资源【2】
【0】获取资源组
[_assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
if (group) {
[_assetsArray addObject:group];
[_tableView reloadData];
}
} failureBlock:^(NSError *error) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"相册获取失败" delegate:self cancelButtonTitle:@"取消" otherButtonTitles: nil];
[alert show];
}];
【1】过滤
[_assetsGroup setAssetsFilter:[ALAssetsFilter allPhotos]];
【2】获取照片资源
- (void)getImages{
_thumbnailMeasure = (SCREEN_WIDTH-(self.numberOfImageEachRow+1)*PHOTO_DEFAULT_MARGIN)/self.numberOfImageEachRow;
CGRect frame = CGRectMake(0, 0, _thumbnailMeasure, _thumbnailMeasure);
[self.assetsGroup enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
if (result) {
AssetView *assetView = [[AssetView alloc]initWithAsset:result WithFrame:frame];
assetView.delegate = self;
[_assetsArray addObject:assetView];
}
}];
}
相关操作
- 获取资源组名
[_assetsGroup valueForProperty:ALAssetsGroupPropertyName];
- 获取资源组的海报缩略图
[UIImage imageWithCGImage:_assetsGroup.posterImage];
- 获取照片资源的正方形缩略图
[UIImage imageWithCGImage:_asset.thumbnail];
- 获取照片资源完全分辨率的图像(先封装图像资源)
[[asset defaultRepresentation] fullResolutionImage]];
- 获取资源类型
[asset valueForProperty:ALAssetPropertyType];
Demo代码已上传github
https://github.com/Lotheve/LXXMutiAlbum
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-11-07 06:37:56