有没有办法将多个选定的图像(使用BSimagePicker)添加到Imageview中?
BSimagePIckerCode
Keyboard.SendKeys()
Imageview代码
@IBAction func showImagePicker(sender: UIButton) {
let vc = BSImagePickerViewController()
vc.maxNumberOfSelections = 10
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)")
}, completion: nil)
}
答案 0 :(得分:2)
要将资产数组转换为图像数组,请将以下代码添加到BSImagePicker的方法中。
首先创建全局资产数组。我在这里创建了
var SelectedAssets = [PHAsset]()
然后调用BSImagepicker的方法添加以下代码。
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)")
print(assets.count)
for i in 0..<assets.count
{
self.SelectedAssets.append(assets[i])
print(self.SelectedAssets)
}
}, completion: nil)
创建一个将您的资产数组转换为图像数组的方法。我在这里创建了一个方法。
func getAllImages() -> Void {
print("get all images method called here")
if SelectedAssets.count != 0{
for i in 0..<SelectedAssets.count{
let manager = PHImageManager.defaultManager()
let option = PHImageRequestOptions()
var thumbnail = UIImage()
option.synchronous = true
manager.requestImageForAsset(SelectedAssets[i], targetSize: CGSize(width: 200, height: 200), contentMode: .AspectFill, options: option, resultHandler: {(result, info)->Void in
thumbnail = result!
})
self.PhotoArray.append(thumbnail)
}
}
ImagesCollectionView.reloadData()
}
在上面的方法中,我使用“集合视图”显示所有选定的图像。
现在执行视图中的选择器方法将在延迟后执行get all images方法。如下:
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.performSelector(#selector(ViewController.getAllImages), withObject: nil, afterDelay: 0.5)
}
那就是它你会得到所选择的图像......希望它能帮助你......