测试已测试 | ✗ |
语言语言 | Obj-CObjective C |
许可证 | MIT |
发布最后发布 | 2016年2月 |
由 Owen Hart 维护。
具有多选支持的 UIImagePickerController 的克隆版。
>= 3.0.0
:iOS 8 或更高版本(使用 PhotoKit)< 3.0.0
:iOS 6 或更高版本(使用 AssetsLibrary)QBImagePickerController *imagePickerController = [QBImagePickerController new];
imagePickerController.delegate = self;
imagePickerController.allowsMultipleSelection = YES;
imagePickerController.maximumNumberOfSelection = 6;
imagePickerController.showsNumberOfSelectedAssets = YES;
[self presentViewController:imagePickerController animated:YES completion:NULL];
QBImagePickerControllerDelegate
方法QBImagePickerController
对象self
设置为 delegate
属性使用 presentViewController:animated:completion:
显示选择器
QBImagePickerController *imagePickerController = [QBImagePickerController new]; imagePickerController.delegate = self;
[self presentViewController:imagePickerController animated:YES completion:NULL];
实现 qb_imagePickerController:didFinishPickingAssets:
以获取用户选定的资产。
当用户完成资产选择时,将调用此方法。
- (void)qb_imagePickerController:(QBImagePickerController *)imagePickerController didFinishPickingAssets:(NSArray *)assets {
for (PHAsset *asset in assets) {
// Do something with the asset
}
[self dismissViewControllerAnimated:YES completion:NULL];
}
通过实现 qb_imagePickerControllerDidCancel:
在用户点击“取消”按钮时接收通知。
- (void)qb_imagePickerControllerDidCancel:(QBImagePickerController *)imagePickerController {
[self dismissViewControllerAnimated:YES completion:NULL];
}
您可以通过实现这些方法来处理用户选择的更改。
- (BOOL)qb_imagePickerController:(QBImagePickerController *)imagePickerController shouldSelectAsset:(PHAsset *)asset;
- (void)qb_imagePickerController:(QBImagePickerController *)imagePickerController didSelectAsset:(PHAsset *)asset;
- (void)qb_imagePickerController:(QBImagePickerController *)imagePickerController didDeselectAsset:(PHAsset *)asset;
当 allowsMultipleSelection
设置为 YES
时,用户可以选择多个照片。
默认值为 NO
。
imagePickerController.allowsMultipleSelection = YES;
您可以通过使用 minimumNumberOfSelection
和 maximumNumberOfSelection
属性来限制选择数量。
默认值为 0
,表示选择数量无限制。
imagePickerController.minimumNumberOfSelection = 3;
imagePickerController.maximumNumberOfSelection = 6;
使用 assetCollectionSubtypes
属性来指定要显示的相册。
以下代码显示了默认值。
imagePickerController.assetCollectionSubtypes = @[
@(PHAssetCollectionSubtypeSmartAlbumUserLibrary), // Camera Roll
@(PHAssetCollectionSubtypeAlbumMyPhotoStream), // My Photo Stream
@(PHAssetCollectionSubtypeSmartAlbumPanoramas), // Panoramas
@(PHAssetCollectionSubtypeSmartAlbumVideos), // Videos
@(PHAssetCollectionSubtypeSmartAlbumBursts) // Bursts
];
相册将按照您指定的顺序排列。
用户的相册将始终显示在智能相册之后。
使用 mediaType
来过滤要显示的资产。
默认值为 QBImagePickerMediaTypeAny
。
imagePickerController.mediaType = QBImagePickerMediaTypeVideo;
有一些属性可以显示有用的信息。
imagePickerController.prompt = @"Select the photos you want to upload!";
imagePickerController.showsNumberOfSelectedAssets = YES;
使用 numberOfColumnsInPortrait
和 numberOfColumnsInLandscape
来更改网格大小。
以下代码显示了默认值。
imagePickerController.numberOfColumnsInPortrait = 4;
imagePickerController.numberOfColumnsInLandscape = 7;
版权所有(c)2015 Katsuma Tanaka
特此授予任何获得此软件及其相关文档副本(“软件”)的人士,在《软件》上使用而不受限制的权利,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或出售《软件》的副本,并允许为此目的提供《软件》的人员这样做,前提是必须遵守以下条件
上述版权声明和本许可声明应包含在《软件》的所有副本或实质性部分中。
《软件》按“原样”提供,不提供任何形式的保证,无论是明示的还是暗示的,包括但不限于适销性、特定目的的适用性和非侵权的保证。在任何情况下,作者或版权持有人均不对任何索赔、损害或其他责任承担责任,无论是由于合同、侵权或其他行为而产生的,也不论与《软件》或其使用或其他处理有关。