我是使用 swift 3 快速编码的新手。
我构建了我的应用程序以成功从 photolib 中选择图像,现在我正在尝试选择多个图像,我想知道ELCImagePickerController
在我的应用程序中使用的步骤。
如何添加库和步骤,让我可以添加其相关代码并在我的 Xcode 中使用控制器及其所有功能?简而言之,如何将第二方定制代码嵌入我的?
我是使用 swift 3 快速编码的新手。
我构建了我的应用程序以成功从 photolib 中选择图像,现在我正在尝试选择多个图像,我想知道ELCImagePickerController
在我的应用程序中使用的步骤。
如何添加库和步骤,让我可以添加其相关代码并在我的 Xcode 中使用控制器及其所有功能?简而言之,如何将第二方定制代码嵌入我的?
工作代码
import UIKit
class ViewController: UIViewController, ELCImagePickerControllerDelegate {
var picker = ELCImagePickerController(imagePicker: ())
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(animated: Bool) {
picker.maximumImagesCount = 5
picker.imagePickerDelegate = self
self.presentViewController(picker, animated: true, completion: nil)
}
func elcImagePickerController(picker: ELCImagePickerController!, didFinishPickingMediaWithInfo info: [AnyObject]!) {
}
func elcImagePickerControllerDidCancel(picker: ELCImagePickerController!) {
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
导入 UIKit 导入照片 导入 BSImagePicker
类视图控制器:UIViewController {
//MARK:- Outlets
@IBOutlet var collView: UICollectionView!
@IBOutlet var img: UIImageView!
//MARK:- Variable
var Select = [PHAsset]()
var arrimg = [UIImage]()
override func viewDidLoad() {
super.viewDidLoad()
// imgPkr.delegate = self }
//MARK:- Button Action
@IBAction func btnSelect(_ sender: AnyObject) {
let imgPkr = BSImagePickerViewController()
self.bs_presentImagePickerController(imgPkr, animated: true, select: {(asset : PHAsset) -> Void in }, deselect: {(asset : PHAsset) -> Void in}, cancel: {(assets : [PHAsset]) -> Void in}, finish: {(assets : [PHAsset]) -> Void in
for i in 0..<assets.count
{
self.Select.append(assets[i])
}
}, completion: nil)}
func getAllImg() -> Void
{
if Select.count != 0{
for i in 0..<Select.count{
let manager = PHImageManager.default()
let option = PHImageRequestOptions()
var thumbnail = UIImage()
option.isSynchronous = true
manager.requestImage(for: Select[i], targetSize: CGSize(width: 200, height: 200), contentMode: .aspectFill, options: option, resultHandler: {(result, info)->Void in
thumbnail = result!
})
self.arrimg.append(thumbnail)
}
}
collView.reloadData()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.perform(#selector(ViewController.getAllImg), with: nil, afterDelay: 0.5)
}
} // MARK:- 集合视图方法
扩展 ViewController : UICollectionViewDataSource,UICollectionViewDelegate{
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return arrimg.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! imgCollectionViewCell
cell.img1.image = arrimg[indexPath.item]
return cell
}
}
//MARK :- 收集单元
类 imgCollectionViewCell: UICollectionViewCell {
@IBOutlet var img1: UIImageView!