ios - 如何在 iOS 中快速使用多个图像选择器

标签 ios swift

我正在制作约会应用程序。 如您所知,用户需要在约会应用中注册多张图片。

所以我知道了如何在一个 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/

相关文章:

ios - 在 viewDidAppear 之前以编程方式定位 UIView

iOS 7 : UINavigationBar out of sync with UINavigationController

iOS - 如何在 AppsFlyer 的 One-Link 中获取参数。应用已安装并启动

ios - 将自定义 tableviewcell 连接到 Uitableview

Swift CORDIC 算法给出不变的答案

xcode - iOS 9 native 应用程序无法通过 https 连接到 mobilefirst 服务器

ios - NavigationController 内的 Swift ImagePicker

android - 这个 opengl 漫反射着色器使我的纹理透明

macos - Swift中的IOBluetoothDeviceSelectorController

Swift:如何使用类名声明属性