-1
我想创建像Instagram库一样的自定义照片视图。如何创建像Instagram一样的自定义照片视图?
默认情况下它显示“相机胶卷”的照片,当我点击它就会显示我的设备的所有专辑列表上的任何专辑或文件夹,点击它会重新与点击相册中的所有照片。
我该怎么做?
我想创建像Instagram库一样的自定义照片视图。如何创建像Instagram一样的自定义照片视图?
默认情况下它显示“相机胶卷”的照片,当我点击它就会显示我的设备的所有专辑列表上的任何专辑或文件夹,点击它会重新与点击相册中的所有照片。
我该怎么做?
您可使用照片框架来获取您的画廊中的所有图像,并显示所有图像根据您的要求
PHFetchResult *smartAlbums = [PHAssetCollection
fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum
subtype:PHAssetCollectionSubtypeAlbumRegular options:nil];
//set up fetch options, mediaType is image.
PHFetchOptions *options = [[PHFetchOptions alloc] init];
options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]];
options.predicate = [NSPredicate predicateWithFormat:@"mediaType = %d",PHAssetMediaTypeImage];
for (NSInteger i =0; i < smartAlbums.count; i++) {
PHAssetCollection *assetCollection = smartAlbums[i];
PHFetchResult *assetsFetchResult = [PHAsset fetchAssetsInAssetCollection:assetCollection options:options];
NSLog(@"sub album title is %@, count is %ld", assetCollection.localizedTitle, (unsigned long)assetsFetchResult.count);
if (assetsFetchResult.count > 0 && ![assetCollection.localizedTitle isEqualToString: @"Recently Deleted"]) {
for (PHAsset *asset in assetsFetchResult) {
//you have got your image type asset.
PHImageRequestOptions *option = [PHImageRequestOptions new];
option.synchronous = YES;
[[PHImageManager defaultManager] requestImageForAsset:asset targetSize:CGSizeMake(self.view.frame.size.width, self.view.frame.size.height-100) contentMode:PHImageContentModeAspectFit options:option resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
[self.imagesURLArray addObject:result];
NSLog(@"asset are %@", asset);
}
}
}
这里是一个很好的图书馆做同样的。
让我来试试这个.. – Kuldeep
会显示专辑名称未在我的照片存在和它会增加重复数据。 – Kuldeep
它将显示iOS提供的所有默认专辑,即总共14张专辑。您可以从相机胶卷获取图像,它将包含您的所有图库图像,然后将所有图像保存到NSMutableArray,然后根据您的要求显示所有图像。如果(assetsFetchResult.count> 0 && [assetCollection.localizedTitle isEqualToString:@“相机胶卷”]) –