2016-05-11 99 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

相關問題