【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];