IRImagePickerController
支持多选的 UIImagePickerController 的克隆版本。
功能
- 允许照片和视频的多选
- 快速且内存效率高地滚动
- 提供类似内置图片选择器的用户界面
- 可定制(网格大小、导航消息等)
- 支持纵向和横向模式
- 兼容 iPhone 6/6Plus 和 iPad
示例
IRImagePickerController *imagePickerController = [IRImagePickerController new];
imagePickerController.delegate = self;
imagePickerController.allowsMultipleSelection = YES;
imagePickerController.maximumNumberOfSelection = 6;
imagePickerController.showsNumberOfSelectedAssets = YES;
[self presentViewController:imagePickerController animated:YES completion:NULL];
安装
Git
- 使用 Git 克隆此项目。
- 将此项目复制到您自己的项目中。
- 将 .xcodeproj 添加到您的项目中,并将其链接为嵌入框架。
选项
- 可以删除
demo
和ScreenShots
文件夹。
CocoaPods
- 在Podfile中添加
pod "IRImagePickerController"
- 运行
pod install
- 将
#import <IRImagePickerController/IRImagePickerController.h>
添加到您的代码中
使用
基本
- 实现
IRImagePickerControllerDelegate
方法 - 创建
IRImagePickerController
对象 - 将
self
设置为delegate
属性 - 使用
presentViewController:animated:completion:
方法显示选择器
IRImagePickerController *imagePickerController = [IRImagePickerController new];
imagePickerController.delegate = self;
[self presentViewController:imagePickerController animated:YES completion:NULL];
代理方法
获取选定的资产
实现ir_imagePickerController:didFinishPickingAssets:
以获取用户选择的资产。
当用户完成资产选择时,将调用此方法。
- (void)ir_imagePickerController:(IRImagePickerController *)imagePickerController didFinishPickingAssets:(NSArray *)assets {
for (PHAsset *asset in assets) {
// Do something with the asset
}
[self dismissViewControllerAnimated:YES completion:NULL];
}
当用户取消时的通知
实现 ir_imagePickerControllerDidCancel:
方法,以在用户点击“取消”按钮时收到通知。
- (void)ir_imagePickerControllerDidCancel:(IRImagePickerController *)imagePickerController {
[self dismissViewControllerAnimated:YES completion:NULL];
}
当用户选择变化时的通知
您可以通过实现以下方法来处理用户选择的变更。
- (BOOL)ir_imagePickerController:(IRImagePickerController *)imagePickerController shouldSelectAsset:(PHAsset *)asset;
- (void)ir_imagePickerController:(IRImagePickerController *)imagePickerController didSelectAsset:(PHAsset *)asset;
- (void)ir_imagePickerController:(IRImagePickerController *)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
过滤要显示的资产。
默认值为 IRImagePickerMediaTypeAny
。
imagePickerController.mediaType = IRImagePickerMediaTypeVideo;
显示信息
有一些属性用于显示有用的信息。
imagePickerController.prompt = @"Select the photos you want to upload!";
imagePickerController.showsNumberOfSelectedAssets = YES;
网格大小
使用 numberOfColumnsInPortrait
和 numberOfColumnsInLandscape
来更改网格大小。
以下代码显示了默认值。
imagePickerController.numberOfColumnsInPortrait = 4;
imagePickerController.numberOfColumnsInLandscape = 7;
合作
该项目很乐意与 IRGallery 合作。查看演示了解如何使用它。
许可证
QBImagePicker 的启发。
该项目受到版权所有 © 2020 Phil。保留所有权利。版权 (c) 2015 Katsuma Tanaka
在此特此授权,不收取任何费用,任何获得此软件及其相关文档副本(统称为“软件”)的个人可以无限制地使用软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本,并允许获得软件的个人进行上述行为,前提是遵守以下条件
上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。
软件按“原样”提供,不包括任何明示或暗示的保证,包括但不限于适销性、特定用途适用性和非侵权的保证。在任何情况下,作者或版权所有者不应对任何索赔、损害或其他责任承担责任,无论该责任是基于合同行为、侵权或其他行为,无论该责任是否源于或与软件的使用或其他处理相关。