一个支持多选图片和视频的图片选择器。采用新的iOS 8 Photo框架。
下载并将GMImagePicker文件夹导入到您的项目中。
#import "GMImagePickerController.h"
GMImagePickerController *picker = [[GMImagePickerController alloc] init];
picker.delegate = self;
[self presentViewController:picker animated:YES completion:nil];
在您的类中实现GMImagePickerControllerDelegate
协议
@interface YourViewController : UIViewController <GMImagePickerControllerDelegate>
实现didFinishPickingAssets
委托方法。请注意,当操作完成时,您负责关闭选择器,并处理返回的(NSArray *)assetArray
- (void)assetsPickerController:(GMImagePickerController *)picker didFinishPickingAssets:(NSArray *)assetArray
{
[picker.presentingViewController dismissViewControllerAnimated:YES completion:nil];
NSLog(@"GMImagePicker: User ended picking assets. Number of selected items is: %lu", (unsigned long)assetArray.count);
}
您还可以实现可选的assetsPickerControllerDidCancel
-(void)assetsPickerControllerDidCancel:(GMImagePickerController *)picker
{
NSLog(@"GMImagePicker: User pressed cancel button");
}
在展示选择器之前,您可以自定义一些属性
...
//Display or not the selection info Toolbar:
picker.displaySelectionInfoToolbar = YES;
//Display or not the number of assets in each album:
picker.displayAlbumsNumberOfAssets = YES;
//Customize the picker title and prompt (helper message over the title)
picker.title = @"Custom title";
picker.customNavigationBarPrompt = @"Custom helper message!";
//Customize the number of cols depending on orientation and the inter-item spacing
picker.colsInPortrait = 3;
picker.colsInLandscape = 5;
picker.minimumInteritemSpacing = 2.0;
//You can pick the smart collections you want to show:
_customSmartCollections = @[@(PHAssetCollectionSubtypeSmartAlbumFavorites),
@(PHAssetCollectionSubtypeSmartAlbumRecentlyAdded),
@(PHAssetCollectionSubtypeSmartAlbumVideos),
@(PHAssetCollectionSubtypeSmartAlbumSlomoVideos),
@(PHAssetCollectionSubtypeSmartAlbumTimelapses),
@(PHAssetCollectionSubtypeSmartAlbumBursts),
@(PHAssetCollectionSubtypeSmartAlbumPanoramas)];
...
也可作为iPad的Popover使用(可自定义大小)
此代码在iPhone和iPad上均适用
...
GMImagePickerController *picker = [[GMImagePickerController alloc] init];
picker.delegate = self;
picker.title = @"Custom title";
picker.customNavigationBarPrompt = @"Custom helper message!";
picker.colsInPortrait = 3;
picker.colsInLandscape = 5;
picker.minimumInteritemSpacing = 2.0;
picker.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *popPC = picker.popoverPresentationController;
popPC.permittedArrowDirections = UIPopoverArrowDirectionAny;
popPC.sourceView = _gmImagePickerButton;
popPC.sourceRect = _gmImagePickerButton.bounds;
[self showViewController:picker sender:nil];
Xcode 6和iOS 8。
MIT许可(MIT)
版权(c)2014 Guillermo Muntaner
hereby granted, any person obtaining a copy of this software and associated documentation files (the "Software") to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions
copy or substantial portions of the Software.
provided "as is", kinds of warranty, express or implied, including but not limited to the warranties of merchantability, suitability for a particular purpose and non-infringement. In no event shall the authors or copyright holders be liable for any claim, damage or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other regulation of the software.