我正在使用第三方库BSImagePicker从图库中选择多个图像。我想在数组中获取这些选定图像的路径,并且我想在新的UIViewController中显示所有选定的图像。我尝试过很多东西,但没有运气。
答案 0 :(得分:1)
嗯,关于github上的文档: https://github.com/mikaoj/BSImagePicker
您确实获得了资产的选择事件
let vc = BSImagePickerViewController()
bs_presentImagePickerController(vc, animated: true,
select: { (asset: PHAsset) -> Void in
// User selected an asset.
// Do something with it, start upload perhaps?
}, deselect: { (asset: PHAsset) -> Void in
// User deselected an assets.
// Do something, cancel upload?
}, cancel: { (assets: [PHAsset]) -> Void in
// User cancelled. And this where the assets currently selected.
}, finish: { (assets: [PHAsset]) -> Void in
// User finished with these assets
}, completion: nil)
非常重要的是要理解,照片库现在不再向图像返回URL,就像使用ALAssetLibrary一样。 现在,您将获得对PHAsset项的引用。这个可能包含多个图像(例如LivePhoto视频和相关的预览图像)。
因此,您可以将所有PHAsset存储在数组中,甚至可以访问图像并存储图像。 (我建议坚持使用PHAsset方法,因为图像可能会炸毁你的内部ram)。
如果您想要显示图像,请在延迟加载方法中使用它:
let options = PHImageRequestOptions()
options.deliveryMode = .HighQualityFormat
options.synchronous = true // Set it to false for async callback
let imageManager = PHCachingImageManager()
imageManager.requestImageForAsset(<!#assetfromaboce#!>,
targetSize: CGSizeMake(CGFloat(100), CGFloat(100)),
contentMode: .AspectFill,
options: options,
resultHandler: { (resultThumbnail : UIImage?, info : [NSObject : AnyObject]?) in
// Assign your thumbnail which is the *resultThumbnail*
}
答案 1 :(得分:0)
请检查其github存储库上的示例。
我在他们的github上找到的一个片段:
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)