IOS开发—自定义多选相册

自定义多选相册

AssetsLibrary框架介绍:
http://blog.csdn.net/daiyibo123/article/details/46851383

主要思路

  1. 导入AssetsLibrary框架
  2. 从资源库中获取获取资源组【0】,过滤【1】照片后在列表中显示组。
  3. 点击资源组进入对应的相册中,获取组中的所有照片资源【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];
        }
    }];
}

相关操作

  1. 获取资源组名

    [_assetsGroup valueForProperty:ALAssetsGroupPropertyName];

  2. 获取资源组的海报缩略图

    [UIImage imageWithCGImage:_assetsGroup.posterImage];

  3. 获取照片资源的正方形缩略图

    [UIImage imageWithCGImage:_asset.thumbnail];

  4. 获取照片资源完全分辨率的图像(先封装图像资源)

    [[asset defaultRepresentation] fullResolutionImage]];

  5. 获取资源类型

    [asset valueForProperty:ALAssetPropertyType];

Demo代码已上传github
https://github.com/Lotheve/LXXMutiAlbum

你可能感兴趣的:(ios开发,ALAsset,多选相册)