QBImagePicker用法详解

https://blog.csdn.net/zyk5219/article/details/50865407

QBImagePicker用法详解

1、简要说明

  • QBImagePicker用于获取iOS本地图像,QBImagePickerController扩展了UIImagePickerController类用于支持图像的多选操作。

QBImagePicker下载地址

2、集成方式

一、通过Cocoapods

  • 将 pod "QBImagePickerController" 添加到Podfile文件中,然后在终端执行命令pod install
  • 在要使用的类中引入头文件

 

#import <QBImagePickerController/QBImagePickerController.h>

 

  • 遵守协议QBImagePickerControllerDelegate

 

@interface ViewController()<QBImagePickerControllerDelegate>

 

  • 创建QBImagePickerController的实例并设置代理

 

  1.  
    QBImagePickerController *imagePickerController =[QBImagePickerController new];
  2.  
    imagePickerController.delegate = self;

 

二、手动

  • 拖拽 QBImagePicker文件夹到你的项目
  • 在要使用的类中引入头文件

 

#import "QBImagePickerController.h"

 

  • 遵守协议QBImagePickerControllerDelegate

 

@interface ViewController()<QBImagePickerControllerDelegate>

 

  • 创建QBImagePickerController的实例并设置代理

 

  1.  
    QBImagePickerController *imagePickerController =[QBImagePickerController new];
  2.  
    imagePickerController.delegate = self;

 

3、主要用法及功能

QBImagePicker用于获取iOS本地图像,并支持获取多个图片或视频。

 

  1.  
    QBImagePickerController *imagePickerController = [QBImagePickerController new];
  2.  
    imagePickerController.delegate = self;
  3.  
    imagePickerController.allowsMultipleSelection = YES;
  4.  
    [self presentViewController:imagePickerController animated:YES completion:nil];

 

1.获取到图像

 

  1.  
    - (void)qb_imagePickerController:(QBImagePickerController *)imagePickerController didFinishPickingAssets:(NSArray *)assets {
  2.  
    for (PHAsset *asset in assets) {
  3.  
    // Do something with the asset
  4.  
    }
  5.  
    [self dismissViewControllerAnimated:YES completion:nil];
  6.  
    }

 

2.取消获取图像

 

  1.  
    - (void)qb_imagePickerControllerDidCancel:(QBImagePickerController *)imagePickerController {
  2.  
    //do something
  3.  
     [self dismissViewControllerAnimated:YES completion:nil];
  4.  
    }

 

3.更改选择图像时获取到通知

 

  1.  
    - (void)qb_imagePickerController:(QBImagePickerController *)imagePickerController didDeselectAsset:(PHAsset *)asset{
  2.  
    NSLog(@"取消选中");
  3.  
    }
  4.  
    - (void)qb_imagePickerController:(QBImagePickerController *)imagePickerController didSelectAsset:(PHAsset *)asset{
  5.  
    NSLog(@"选中");
  6.  
    }
  7.  
    - (BOOL)qb_imagePickerController:(QBImagePickerController *)imagePickerController shouldSelectAsset:(PHAsset *)asset{
  8.  
    return YES;
  9.  
    }

 

4.设置选择图像数量

 

  1.  
    imagePickerController.allowsMultipleSelection = YES;//允许多选(默认是NO,不允许多选)
  2.  
    imagePickerController.minimumNumberOfSelection = 3;//设置选择图像数量下限
  3.  
    imagePickerController.maximumNumberOfSelection = 6;//设置选择图像数量上限

 

5.指定要显示的相册

 

  1.  
    imagePickerController.assetCollectionSubtypes = @[
  2.  
    @(PHAssetCollectionSubtypeSmartAlbumUserLibrary), //相机胶卷
  3.  
    @(PHAssetCollectionSubtypeAlbumMyPhotoStream), //我的照片流
  4.  
    @(PHAssetCollectionSubtypeSmartAlbumPanoramas), //全景图
  5.  
    @(PHAssetCollectionSubtypeSmartAlbumVideos), //视频
  6.  
    @(PHAssetCollectionSubtypeSmartAlbumBursts) //连拍模式拍摄的照片
  7.  
    ];

 

6.设置媒体类型

 

  1.  
    imagePickerController.mediaType = QBImagePickerMediaTypeAny;//图片和视频
  2.  
    imagePickerController.mediaType = QBImagePickerMediaTypeImage;//图片
  3.  
    imagePickerController.mediaType = QBImagePickerMediaTypeVideo;//视频

 

7.设置每行显示的图像数量

 

  1.  
    imagePickerController.numberOfColumnsInPortrait = 4;//竖屏模式下一行显示4张图像
  2.  
    imagePickerController.numberOfColumnsInLandscape = 7;//横屏模式下一行显示7张图像

 

8.显示提示信息

 

  1.  
    imagePickerController.prompt = @"请选择图像!";//在界面上方显示文字“请选择图像!”
  2.  
    imagePickerController.showsNumberOfSelectedAssets = NO;//在界面下方显示已经选择图像的数量

 

 

 4、当前版本

posted @ 2018-08-24 10:45  sundaysios  阅读(540)  评论(0)    收藏  举报