在这里,我已经使用第三方库BSImagePicker在我们的库中进行了多次选择。选择图像后,我将无法保存并显示在图像视图中。我希望将图像保存并在收藏视图中显示。我已经导入了照片和BSImagePicker。
如果我单击showImagepicker,则可以选择多个图像,并且应将其放置在各自的位置。我已经使用4个图像视图来设置我们选择的图像。 这是我的代码:
compute.instances.insert
这是collectionviewcell的自定义视图类:
class ViewController: UIViewController ,UICollectionViewDataSource,UICollectionViewDelegate{
@IBAction func showImagePicker(_ sender: UIButton) {
let vc = BSImagePickerViewController()
vc.maxNumberOfSelections = 4
bs_presentImagePickerController(vc, animated: true,
select: { (asset: PHAsset) -> Void in
print("Selected: \(asset)")
}, deselect: { (asset: PHAsset) -> Void in
print("Deselected: \(asset)")
}, cancel: { (assets: [PHAsset]) -> Void in
print("Cancel: \(assets)")
}, finish: { (assets: [PHAsset]) -> Void in
print("Finish: \(assets)")
if let imageView = vc.imageview{
PHCachingImageManager.default().requestImage(for: asset, targetSize:imageView.frame.size, contentMode: .aspectFit, options: options) { (result, _) in
imageView.image = result
}
}
}, completion: nil)
}
@IBOutlet weak var collectionview: UICollectionView!
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 4
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionview.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! CollectionViewCell
cell.imagecollection.image = imageview[indexPath.row]
return cell
}
我已经使用了图像视图的4个插座。我需要保存在该图像视图中。
答案 0 :(得分:0)
我为此找到了解决方案。
全局声明
var Select = PHAsset
var arrimg = UIImage
@IBAction函数showImagePicker(_发件人:UIButton){
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)}
@objc 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: 300, height: 300), contentMode: .aspectFill, options: option, resultHandler: {(result, info)->Void in
thumbnail = result!
})
self.arrimg.append(thumbnail)
}
}
collectionview.reloadData()
}