我Bsimagepicker
允许我选择 3 个图像并将它们放在一个页面中UIScrollView
,但前两个图像丢失并且最后一个图像显示。在某些事情发生变化之前,我已经让它工作了。所以图像选择器应该选择最多 3 张图像并将图像放在带有页面指示器的分页滚动视图中,这样您就可以看到您正在查看的图库中的图像。任何帮助将非常感激
@objc func uploadImg( sender: UIButton) {
PhotoArray.removeAll()
SelectedAssets.removeAll()
self.fillImg.isHidden = true
let imagePicker = ImagePickerController()
imagePicker.settings.selection.max = 3
imagePicker.settings.theme.selectionStyle = .numbered
imagePicker.settings.fetch.assets.supportedMediaTypes = [.image]
imagePicker.settings.selection.unselectOnReachingMax = true
let start = Date()
self.presentImagePicker(imagePicker, select: { (asset) in
print("Selected: \(asset)")
}, deselect: { (asset) in
print("Deselected: \(asset)")
}, cancel: { (assets) in
print("Canceled with selections: \(assets)")
}, finish: { (assets) in
for i in 0..<assets.count
{
self.SelectedAssets.append(assets[i])
}
self.convertAssetToImages()
print("Finished with selections: \(assets)")
}, completion: {
let finish = Date()
print(finish.timeIntervalSince(start))
})
}
func convertAssetToImages() -> Void {
if SelectedAssets.count != 0{
for i in 0..<SelectedAssets.count{
let manager = PHImageManager.default()
let option = PHImageRequestOptions()
var thumbnail = UIImage()
option.isSynchronous = true
manager.requestImage(for: SelectedAssets[i], targetSize: CGSize(width: 1000, height: 1000), contentMode: .aspectFill, options: option, resultHandler: {(result, info)->Void in
thumbnail = result!
})
let data = thumbnail.jpegData(compressionQuality: 0.7)
let newImage = UIImage(data: data!)
self.PhotoArray.append(newImage! as UIImage)
scrollImg.image = PhotoArray[i]
scrollImg.contentMode = .scaleAspectFill
let xPosition = scrollView.frame.width * CGFloat(i)
scrollImg.clipsToBounds = true
scrollImg.frame = CGRect(x: xPosition, y: 0, width: scrollView.frame.width , height: scrollView.frame.height)
scrollView.contentSize.width = scrollView.frame.width * CGFloat(PhotoArray.count)
self.pageC.numberOfPages = PhotoArray.count
scrollView.addSubview(scrollImg)
}
}
}