我正在制作约会应用程序。 如您所知,用户需要在约会应用中注册多张图片。
所以我知道了如何在一个 View 中使用 1 个图像选择器。
但我不知道如何添加多个图像选择器。
我知道我只能用一个
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
}
和
func imagePickerControllerDidCancel(picker: UIImagePickerController) {
picker.dismissViewControllerAnimated(false, completion:nil)
}
所以我找不到多图像选择器 View 的解决方案。
我失败的代码如下。
import UIKit
class RegisterPicture : UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
@IBAction func pick1(sender: AnyObject) {
let picker1 = UIImagePickerController()
picker1.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum
picker1.allowsEditing = true
picker1.delegate = self
self.presentViewController(picker1, animated: false, completion: nil)
}
@IBAction func pick2(sender: AnyObject) {
let picker2 = UIImagePickerController()
picker2.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum
picker2.allowsEditing = true
picker2.delegate = self
self.presentViewController(picker2, animated: false, completion: nil)
}
@IBOutlet var picture1: UIImageView!
@IBOutlet var picture2: UIImageView!
func imagePickerController(picker1: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
picker1.dismissViewControllerAnimated(false, completion : nil)
self.picture1.image = info[UIImagePickerControllerOriginalImage] as? UIImage
}
func imagePickerController(picker2: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
picker2.dismissViewControllerAnimated(false, completion : nil)
self.picture2.image = info[UIImagePickerControllerOriginalImage] as? UIImage
}
func imagePickerControllerDidCancel(picker1: UIImagePickerController) {
picker1.dismissViewControllerAnimated(false, completion:nil)
}
func imagePickerControllerDidCancel(picker2: UIImagePickerController) {
picker2.dismissViewControllerAnimated(false, completion:nil)
}
}
最佳答案
对于 2020 年搜索此内容的任何人,Apple 在 iOS14 中引入了 PHPickerViewController
。这是文档:https://developer.apple.com/documentation/photokit/phpickerviewcontroller
以及解释其用法的WWDC介绍: https://developer.apple.com/videos/play/wwdc2020/10652/
关于ios - 如何在 iOS 中快速使用多个图像选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37166675/