参考资料
相关原理
1. 从本地相册中提取所有的图面内容,并直接将获取到的图片放到一个数组中传到自定义页面中
#pragma mark 加载本地相册的所有图片
-(void)loadLocalPhotos{
ALAssetsLibrary *assetsLibrary = [[ALAssetsLibrary alloc] init];
self.photoArray = [NSMutableArray array];
[assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
//相册分组 group
if (group) {
if([[group valueForProperty:ALAssetsGroupPropertyType] intValue] == 16) //表示是系统默认的相册
{
/*
//查看相册的名字
NSLog(@"ALAssetsGroupPropertyName:%@",[group valueForProperty:ALAssetsGroupPropertyName]);
//查看相册的类型
NSLog(@"ALAssetsGroupPropertyType:%@",[group valueForProperty:ALAssetsGroupPropertyType]);
*/
[group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
if (result) {
//获取资源图片的详细资源信息
ALAssetRepresentation* representation = [result defaultRepresentation];
/*
//获取资源图片的长宽
CGSize dimension = [representation dimensions];
//获取资源图片的高清图
[representation fullResolutionImage];
//获取资源图片的全屏图
[representation fullScreenImage];
//获取资源图片的名字
[representation filename];
//缩放倍数
[representation scale];
//图片资源容量大小
[representation size];
//图片资源原数据
[representation metadata];
//旋转方向
[representation orientation];
//资源图片url地址,该地址和ALAsset通过ALAssetPropertyAssetURL获取的url地址是一样的
NSURL* url = [representation url];
//资源图片uti,唯一标示符
[representation UTI];
*/
//把本地所有图片放在数组
NSDictionary *dictionary = @{
@"thumbnail":[UIImage imageWithCGImage:[result thumbnail]],
@"representation":representation
};
[self.photoArray addObject:dictionary];
}
}];
//这里处理你的业务
//NSLog(@"%zd",self.photoArray.count);
ChosePhotoController *photo = [[ChosePhotoController alloc] init];
photo.photoArray = self.photoArray;
//设置代理
photo.photoDelegate = self;
[self presentViewController:photo animated:YES completion:^{
//
}];
}
}
} failureBlock:^(NSError *error) {
//图片获取失败
}];
}
2. 在自定义页面中进行显示图片,本实例使用的是cell显示,每行显示4个
NSUInteger localtion = indexPath.row * PhotoColumn;
NSUInteger length = PhotoColumn;
if(localtion + PhotoColumn > self.photoArray.count)
{
length = self.photoArray.count - localtion;
}
NSRange range = NSMakeRange(localtion , length);//截取数组
NSArray *rangeArray = [self.photoArray subarrayWithRange:range];