簡介
仿微信的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)
}
複製程式碼