TTAImagePickerController
英语 | 中文
一个轻量级图像选择框架
特性
- 一个轻量级图像选择框架,内存消耗低
- 支持设备方向和 iPad
- 几乎与
UIImagePickerController
接口完全相同,易于入门 - 方便的预览功能
- 许多小细节
屏幕截图
示例
要运行示例项目,请克隆仓库,然后从 Example
目录首先运行 pod install
需求
- iOS > 8.0
- swift >= 5.0
安装
-
TTAImagePickerController
通过 CocoaPods 提供。要安装它,只需在您的 Podfile 中添加以下行:pod "TTAImagePickerController"
-
手动导入:将
TTAImagePickerController
文件夹中的所有文件拖放到项目中,导入主文件:import TTAImagePickerController
如何使用
1. 创建
// Create the image picker with the assets that you had selected which will show as selected in the picker
let imagePicker = TTAImagePickerController(selectedAsset: selectedAssets)
// Set pickerDelegate
imagePicker.pickerDelegate = self
// Set allow take picture in the picker, default: true
imagePicker.allowTakePicture = allowTakePickerSwitch.isOn
// Set allow user delete images in the picker, default: false
imagePicker.allowDeleteImage = allowDeleteImageSwitch.isOn
// Set support large titles for iOS 11
imagePicker.supportLargeTitles = showLargeTitles.isOn
// Set the max pick number, default is 9
imagePicker.maxPickerNum = Int(maxImageCountTextField.text ?? "9") ?? 9
// You can custom the picker apperance
// imagePicker.selectItemTintColor = .red
// imagePicker.barTintColor = .orange
// imagePicker.tintColor = .cyan
present(imagePicker, animated: true, completion: nil)
2. 确认并实现代理
// implement the delegate method and when finished picking, you will get the images and assets that you have selected
func imagePickerController(_ picker: TTAImagePickerControllerCompatiable, didFinishPicking images: [UIImage], assets: [TTAAsset]) {
print("got the images")
selectedImages = images
selectedAssets = assets
imagesCollectionView.reloadData()
}
您可以得到的其他功能
// On the other hand, you can preview the images directly and deselected some of them
// What you need to do:
// Create a instance of `TTAPreviewViewController` (dependency the delegate in step 2)
extension ViewController: UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
collectionView.deselectItem(at: indexPath, animated: true)
let previewVc = TTAPreviewViewController(selected: selectedAssets, index: indexPath.item, delegate: self)
present(previewVc, animated: true, completion: nil)
}
}
最近添加
- 20190328
新增:添加 swift5.0 支持
- 20170917
修复重复选择和删除图片错误 添加 iOS 11 支持 添加 iPhone 支持
- 20170820
添加相机支持 支持在选择器中删除图片
- 20170806
添加 Gif 支持 添加视频支持
下一步
- 您的建议很受欢迎
作者
TobyoTenma, [email protected]
许可
TTAImagePickerController 可在 MIT 许可下使用。有关更多信息,请参阅 LICENSE 文件。