ios 选择多个图像(UIImagePickerController 或 Photos.app Share UI)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1291270/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Select Multiple Images (UIImagePickerController or Photos.app Share UI)
提问by Itay
In iPhone OS 3.0, Apple added the ability to share multiple pictures at once using the "Share" button and selecting multiple images (where a checkmark is used).
在 iPhone OS 3.0 中,Apple 添加了使用“共享”按钮并选择多个图像(使用复选标记)一次共享多张图片的功能。
I'd love to have a UIImagePickerController which lets the user select multiple images at once, rather than having to go one by one. Is there a way to do this, or do I have to wait until they add this feature?
我很想拥有一个 UIImagePickerController,它可以让用户一次选择多个图像,而不必一张一张地选择。有没有办法做到这一点,还是我必须等到他们添加此功能?
回答by Utsav Dusad
Try this wonderful API in swift: ImagePicker. As all other image APIs, it is simple to use and it is very well updated.
在 swift 中试试这个美妙的 API:ImagePicker。与所有其他图像 API 一样,它易于使用且更新得非常好。
回答by Govind Wadhwa
1.install pod - pod "BSImagePicker", "~> 2.8"
1.安装pod - pod "BSImagePicker", "~> 2.8"
- inside info plist add row Privacy - Photo Library Usage Description
- 内部信息 plist 添加行 隐私 - 照片库使用说明
3.paste below code inside a .swift file-
3.将下面的代码粘贴到 .swift 文件中-
import UIKit
import BSImagePicker
import Photos
class MultipleImgViC: UIViewController {
@IBOutlet weak var imageView: UIImageView!
var SelectedAssets = [PHAsset]()
var photoArray = [UIImage]()
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func selectImages(_ sender: Any) {
let vc = BSImagePickerViewController()
self.bs_presentImagePickerController(vc, animated: true, select: { (assest: PHAsset) -> Void in
},
deselect: { (assest: PHAsset) -> Void in
}, cancel: { (assest: [PHAsset]) -> Void in
}, finish: { (assest: [PHAsset]) -> Void in
for i in 0..<assest.count
{
self.SelectedAssets.append(assest[i])
}
self.convertAssetToImages()
}, completion: nil)
}
@IBAction func dismissview(_ sender: Any) {
dismiss(animated: true, completion: nil)
}
}
extension MultipleImgViC{
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: 200, height: 200), 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)
}
self.imageView.animationImages = self.photoArray
self.imageView.animationDuration = 3.0
self.imageView.startAnimating()
}
}
}
Note :- if pod file give "How to fix “SWIFT_VERSION '3.0' is unsupported, supported versions are: 4.0, 4.2, 5.0” error in Xcode 10.2? " this error then solve it from this link:- https://stackoverflow.com/a/55901964/8537648
注意:- 如果 pod 文件给出“How to fix “SWIFT_VERSION '3.0' is unsupported, supported versions are: 4.0, 4.2, 5.0” error in Xcode 10.2? ”这个错误然后从这个链接解决它:- https://stackoverflow .com/a/55901964/8537648
video reference: - https://youtu.be/B1DelPi1L0U
视频参考: - https://youtu.be/B1DelPi1L0U
回答by Letaief Achraf
You can use this OpalImagePickerlike this (Swift 4):
您可以像这样使用OpalImagePicker (Swift 4):
var imagePicker: OpalImagePickerController!
imagePicker = OpalImagePickerController()
imagePicker.imagePickerDelegate = self
imagePicker.selectionImage = UIImage(named: "aCheckImg")
imagePicker.maximumSelectionsAllowed = 3 // Number of selected images
present(imagePicker, animated: true, completion: nil)
And then implement its delegate:
然后实现它的委托:
func imagePickerDidCancel(_ picker: OpalImagePickerController) {
//Cancel action
}
func imagePicker(_ picker: OpalImagePickerController, didFinishPickingImages images: [UIImage]) {
}
回答by Thomas Decaux
AssetLibrary + UICollectionView ^^
AssetLibrary + UICollectionView ^^
Basically, with StoryBoard, you import aUINavigationController
, you change the root controller to anUICollectionViewController
(will be your Album list), end add anotherUICollectionViewController
(will be your photos list).
基本上,使用 StoryBoard,您导入一个UINavigationController
,将根控制器更改为一个UICollectionViewController
(将是您的相册列表),最后添加另一个UICollectionViewController
(将是您的照片列表)。
Then with Assetlibrary you retrieve user albums and user album content.
然后使用 Assetlibrary 检索用户相册和用户相册内容。
I will make a such component as soon as i have some time.
我一有时间就会制作一个这样的组件。
回答by Forrest
How about this way:
这种方式怎么样:
Open "photos.app" first, select multiple photos , and copy them ;
In your own app, try to retrieve those copies photos;
首先打开“photos.app”,选择多张照片,复制;
在您自己的应用程序中,尝试检索那些副本照片;
I knew that there are some apps did like this, but do not know how can achieve step 2.
我知道有一些应用程序是这样做的,但不知道如何实现第 2 步。