1、简要说明
- QBImagePicker用于获取iOS本地图像,QBImagePickerController扩展了UIImagePickerController类用于支持图像的多选操作。
2、集成方式
一、通过Cocoapods
- 将 pod "QBImagePickerController" 添加到Podfile文件中,然后在终端执行命令pod install
- 在要使用的类中引入头文件
#import <QBImagePickerController/QBImagePickerController.h>
- 遵守协议QBImagePickerControllerDelegate
@interface ViewController()<QBImagePickerControllerDelegate>
- 创建QBImagePickerController的实例并设置代理
QBImagePickerController *imagePickerController =[QBImagePickerController new];
imagePickerController.delegate = self;
二、手动
- 拖拽 QBImagePicker文件夹到你的项目
- 在要使用的类中引入头文件
#import "QBImagePickerController.h"
- 遵守协议QBImagePickerControllerDelegate
@interface ViewController()<QBImagePickerControllerDelegate>
- 创建QBImagePickerController的实例并设置代理
QBImagePickerController *imagePickerController =[QBImagePickerController new];
imagePickerController.delegate = self;
3、主要用法及功能
QBImagePicker用于获取iOS本地图像,并支持获取多个图片或视频。
QBImagePickerController *imagePickerController = [QBImagePickerController new];
imagePickerController.delegate = self;
imagePickerController.allowsMultipleSelection = YES;
[self presentViewController:imagePickerController animated:YES completion:nil];
1.获取到图像
- (void)qb_imagePickerController:(QBImagePickerController *)imagePickerController didFinishPickingAssets:(NSArray *)assets {
for (PHAsset *asset in assets) {
// Do something with the asset
}
[self dismissViewControllerAnimated:YES completion:nil];
}
2.取消获取图像
- (void)qb_imagePickerControllerDidCancel:(QBImagePickerController *)imagePickerController {
//do something
[self dismissViewControllerAnimated:YES completion:nil];
}
3.更改选择图像时获取到通知
- (void)qb_imagePickerController:(QBImagePickerController *)imagePickerController didDeselectAsset:(PHAsset *)asset{
NSLog(@"取消选中");
}
- (void)qb_imagePickerController:(QBImagePickerController *)imagePickerController didSelectAsset:(PHAsset *)asset{
NSLog(@"选中");
}
- (BOOL)qb_imagePickerController:(QBImagePickerController *)imagePickerController shouldSelectAsset:(PHAsset *)asset{
return YES;
}
4.设置选择图像数量
imagePickerController.allowsMultipleSelection = YES;//允许多选(默认是NO,不允许多选)
imagePickerController.minimumNumberOfSelection = 3;//设置选择图像数量下限
imagePickerController.maximumNumberOfSelection = 6;//设置选择图像数量上限
5.指定要显示的相册
imagePickerController.assetCollectionSubtypes = @[
@(PHAssetCollectionSubtypeSmartAlbumUserLibrary), //相机胶卷
@(PHAssetCollectionSubtypeAlbumMyPhotoStream), //我的照片流
@(PHAssetCollectionSubtypeSmartAlbumPanoramas), //全景图
@(PHAssetCollectionSubtypeSmartAlbumVideos), //视频
@(PHAssetCollectionSubtypeSmartAlbumBursts) //连拍模式拍摄的照片
];
6.设置媒体类型
imagePickerController.mediaType = QBImagePickerMediaTypeAny;//图片和视频
imagePickerController.mediaType = QBImagePickerMediaTypeImage;//图片
imagePickerController.mediaType = QBImagePickerMediaTypeVideo;//视频
7.设置每行显示的图像数量
imagePickerController.numberOfColumnsInPortrait = 4;//竖屏模式下一行显示4张图像
imagePickerController.numberOfColumnsInLandscape = 7;//横屏模式下一行显示7张图像
8.显示提示信息
imagePickerController.prompt = @"请选择图像!";//在界面上方显示文字“请选择图像!”
imagePickerController.showsNumberOfSelectedAssets = NO;//在界面下方显示已经选择图像的数量
4、当前版本
3.4.0