swift - 快速图像选择器获取多张图片
问题描述
我在使用 ImagePicker 将图像插入 CollectionView 单元格时遇到问题。问题是,如果我单击要快速插入几次的照片,则该照片会在不同的单元格中插入多次。
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
picker.dismiss(animated: true, completion: nil)
picker.allowsEditing = true
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
collectionViewController?.imageArray.append(pickedImage)
collectionViewController?.newImages.append(pickedImage)
let guid = UUID()
let fileManager = FileManager.default
let imagePath = (NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as NSString).appendingPathComponent("\(guid).png")
let data = UIImagePNGRepresentation(fixOrientation(img: pickedImage))
fileManager.createFile(atPath: imagePath as String, contents: data, attributes: nil)
let image = CoreDataManager.shared.createImageyObject(pfad: imagePath, date: Date(), guid: guid)
collectionViewController?.images.append(image)
if collectionViewController?.images.count == 1 {
collectionViewController?.images[0].isBaseImage = true
collectionViewController?.lastIndex = 0
}
collectionViewController?.update()
}
}
解决方案
Mediainfo 包含图像 url,媒体 url ...也许您应该在 Set 中缓存选择的 imageURL(唯一的),然后检查 imageURL 是否已经存在。
推荐阅读
- html - “选择”标签的纯 CSS 浮动标签
- c# - 如何创建一个静态全局事件,以便一个表单可以监听另一个表单的不是父表单的事件?
- javascript - 如何在 10 秒不活动后显示弹出窗口
- javascript - 如何为 jquery 1.x 修复 chrome 的非被动元素问题
- android-studio - Android Studio 中隐藏/显示预览的快捷方式
- c# - 从输入字符串中释放 .exe 文件作为代码
- jena - 使用 OWL API 加载在 Turtle 中序列化的 Ontology
- css - 如果一个人的身高发生变化,如何更改所有 div 的高度
- css - 如何将预先存在的 css 类附加到 Cytoscape JS for Angular 中的节点标签
- java - 当页面中存在两个框架时如何移动物理鼠标