RGImagePicker is a component which could help you elegantly pick image, gif, video and LivePhoto
-
Transition animations and interaction gestures like system "Photos" app. Presentation at RGImageGallery
-
Pick Image
-
Long Tap for Displaying presentingViewController
-
Pick GIF
-
Pick Video
-
Pick LivePhoto
-
iCloud Support
-
High Performance When Quickly Slide (There are 16000 photos in presentation)
-
Customizable pick resource type
-
Customizable picker UI
Add via CocoaPods by adding this to your Podfile:
pod 'RGImagePicker'
#import <RGImagePicker/RGImagePicker.h>
+ (RGImagePickerConfig *)onlyImageConfigWithBackgroundImage:(UIImage *)backgroundImage {
RGImagePickerConfig *config = [RGImagePickerConfig new];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"mediaType = %d", PHAssetMediaTypeImage];
PHFetchOptions *option = [[PHFetchOptions alloc] init];
option.predicate = predicate;
config.option = option;
config.backgroundImage = backgroundImage;
config.backgroundBlurRadius = 3.5;
config.tintColor = [UIColor blackColor];
config.privacyDescriptionString = @"App 没有权限访问您的相册\n\n请前往设置 打开权限";
/*
// Cutom smart album list if need
NSMutableArray *array = [NSMutableArray array];
[array addObject:@(PHAssetCollectionSubtypeSmartAlbumUserLibrary)];
[array addObject:@(PHAssetCollectionSubtypeSmartAlbumFavorites)];
[array addObject:@(PHAssetCollectionSubtypeSmartAlbumTimelapses)];
[array addObject:@(PHAssetCollectionSubtypeSmartAlbumRecentlyAdded)];
if (@available(iOS 10.3, *)) {
[array addObject:@(PHAssetCollectionSubtypeSmartAlbumLivePhotos)];
}
[array addObject:@(PHAssetCollectionSubtypeSmartAlbumPanoramas)];
if (@available(iOS 9.0, *)) {
[array addObject:@(PHAssetCollectionSubtypeSmartAlbumSelfPortraits)];
}
config.cutomSmartAlbum = array;
// Push into this album at first
config.defaultType = PHAssetCollectionSubtypeSmartAlbumFavorites;
*/
return config;
}
RGImagePickerConfig *config = [self onlyImageConfigWithBackgroundImage:self.backgroundView.image];
[RGImagePicker presentByViewController:self maxCount:10 config:config pickResult:^(NSArray<PHAsset *> * _Nonnull phassets, UIViewController * _Nonnull pickerViewController) {
// Began multi load resource
}];
Present by yourself
RGImagePickerConfig *config = [self onlyImageConfigWithBackgroundImage:self.backgroundView.image];
UINavigationController *nvc = [RGImagePicker pickerWithMaxCount:10 config:config pickResult:^(NSArray<PHAsset *> * _Nonnull phassets, UIViewController * _Nonnull pickerViewController) {
// Began multi load resource
}];
nvc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:nvc animated:YES completion:nil];
// LoadOption tell picker load rules
RGImagePickerLoadOption option = RGImagePickerLoadVideoFirst|RGImagePickerLoadVideoMediumQuality|RGImagePickerLoadNeedLivePhoto;
[RGImagePicker loadResourceFromAssets:phassets
loadOption:option
thumbSize:CGSizeMake(1280, 1280)
completion:^(NSArray<NSDictionary *> * _Nonnull infos, NSError * _Nullable error) {
if (error) {
return;
}
// Handle resource data
// 🙋 There is a example from the demo that Presentation in above GIF
[self.presentingViewController dismissViewControllerAnimated:YES completion:^{
[infos enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull info, NSUInteger idx, BOOL * _Nonnull stop) {
// get resource in info
NSData *imageData = info[RGImagePickerResourceData];
NSData *thumbData = info[RGImagePickerResourceThumbData];
if (!imageData.length) {
return;
}
if (!thumbData.length) {
thumbData = imageData;
}
PHAsset *asset = phassets[idx];
NSString *filename = info[RGImagePickerResourceFilename];
NSString *thumbName = nil;
BOOL isGif = [[info[RGImagePickerResourceUTI] lowercaseString] containsString:@"gif"];
if (isGif) {
thumbName = [asset.localIdentifier stringByAppendingPathComponent:filename];
thumbData = imageData;
} else {
thumbName = [asset.localIdentifier stringByAppendingPathComponent:[NSString stringWithFormat:@"thumb-%@", filename]];
}
// construct message model
RGMessage *model = [RGMessage new];
// write data to path
NSString *path = [CTFileManger.cacheManager createFile:thumbName atFolder:UCChatDataFolderName data:thumbData];
if (!path.length) {
return;
}
model.thumbUrl = thumbName;
model.thumbSize = info[RGImagePickerResourceThumbSize];
filename = [asset.localIdentifier stringByAppendingPathComponent:filename];
if (!isGif) {
path = [CTFileManger.cacheManager createFile:filename atFolder:UCChatDataFolderName data:imageData];
if (!path.length) {
return;
}
}
model.originalImageUrl = filename;
model.originalImageSize = info[RGImagePickerResourceSize];
[self insertChatData:model];
}];
}];
}];
- Image Edit
- Picker Sort
- Pick from Camera