简介
仿微信的iOS相册选择库
项目主页:MTImagePicker
特性
- 支持多选,图片/视频混选。
- 兼容iOS7,支持指定使用ALAssets或者Photos框架。
- 支持相册选择
- 预览滚动流畅优化
导入
直接导入 无其他依赖,直接拖动MTImagePicker/MTImagePicker
到你的项目就行 CocoaPods
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
pod 'MTImagePicker', '~> 3.0.2'
复制代码
使用
- 用法类似
UIImagePickerController
let imagePicker = MTImagePickerController.instance
imagePicker.mediaTypes = [MTImagePickerMediaType.Photo,MTImagePickerMediaType.Video] // 选择类别
imagePicker.imagePickerDelegate = self
imagePicker.maxCount = 10 // 最大选取数目
imagePicker.defaultShowCameraRoll = true // 是否直接进入默认相册,如果是true则像微信一样跳过相册选择,直接进入相机胶卷
复制代码
- 可以指定source来确定使用ALAsset还是Photos框架
//默认为MTImagePickerSource.ALAsset
imagePicker.source = MTImagePickerSource.ALAsset
//imagePicker.source = MTImagePickerSource.Photos (iOS8+)
复制代码
- presentViewController唤起界面
self.presentViewController(imagePicker, animated: true, completion: nil)
复制代码
- 根据选择的source框架,实现代理方法
@objc protocol MTImagePickerControllerDelegate:NSObjectProtocol {
// ALAsset框架代理
optional func imagePickerController(picker:MTImagePickerController, didFinishPickingWithAssetsModels models:[MTImagePickerAssetsModel])
// Photos框架代理
@available(iOS 8.0, *)
optional func imagePickerController(picker:MTImagePickerController, didFinishPickingWithPhotosModels models:[MTImagePickerPhotosModel])
// 取消代理
optional func imagePickerControllerDidCancel(picker: MTImagePickerController)
}
复制代码