2016-05-11 133 views
0

我正在约会应用程序。如你所知,用户需要在约会应用程序中注册多张图片。如何在iOS中使用多个图像选择器与swift

所以我得到了如何在一个视图中使用1个图像选择器。

但我不知道如何添加多个图像选择器。

我知道我只可以只用一个

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) { 
} 

func imagePickerControllerDidCancel(picker: UIImagePickerController) { 
    picker.dismissViewControllerAnimated(false, completion:nil) 
} 

,所以我不能找到多个imagepicker 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) 

} 
} 
+0

你可以在这里找到一个伟大的答案:http://stackoverflow.com/questions/20756899/how-to-select-multiple-images-from-uiimagepickercontroller 我遇到了你同样的情况,发现好在这里回答。 – truongky

回答

1

您无法使用UIImagePickerController选择多个图像。您必须制作自己的自定义图像选择器,或者使用第三方这样的one

+0

然后我必须学习自定义图像选择器 – kimpro

+0

然后我只是复制如何做一些像这样的一些库:https://github.com/zhangao0086/DKImagePickerController/blob/master/DKImagePickerController/DKImagePickerController.swift – Jaime

1

我试着找到一个类似于iOS照片应用程序的UX的选择器,该应用程序专门为资产同步进行了优化,但是我找不到这样的控制器,最后我做了我自己的。它具有强大的定制能力,并支持多选,自定义排序&筛选,并完全用现代Swift 3.0编写。如果有人发现它的错误,我会为你修复它们:) 你可以试试这个链接。 https://github.com/DragonCherry/AssetsPickerViewController

相关问题