var imagePicker = UIImagePickerController() @IBAction func chooseImage1(sender: AnyObject) { if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.SavedPhotosAlbum){ println("button capture") imagePicker.delegate = self imagePicker.sourceType = .SavedPhotosAlbum imagePicker.allowsEditing = false self.presentVIEwController(imagePicker,animated: true,completion: nil) }}@IBAction func chooseImage2(sender: AnyObject) { if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.SavedPhotosAlbum){ println("button capture") imagePicker2.delegate = self imagePicker2.sourceType = .SavedPhotosAlbum imagePicker2.allowsEditing = false self.presentVIEwController(imagePicker,completion: nil)}}func imagePickerController(picker: UIImagePickerController,dIDFinishPickingMediawithInfo info: [NSObject : AnyObject]) { let pickedImage = info[UIImagePickerControllerOriginalimage] as? UIImage chooseImage1.image = pickedImage let pickedImage2 = info[UIImagePickerControllerOriginalimage] as? UIImage chooseImage2.image = pickedImage2 dismissVIEwControllerAnimated(true,completion: nil)}func imagePickerControllerDIDCancel(picker: UIImagePickerController) { dismissVIEwControllerAnimated(true,completion: nil)}
这最终为每个不同的图像视图选择相同的图像.我希望能够选择两张单独的照片,每张照片一张.谢谢您的帮助.
解决方法 您可以将每个按钮设置为不同的标签,并根据按钮的标签更新一个imageVIEw或另一个.你只需要一个UIImagePickerController:更新:Xcode 8.3.1•Swift 3.1
import UIKitclass VIEwController: UIVIEwController,UIImagePickerControllerDelegate,UINavigationControllerDelegate { @IBOutlet weak var imageVIEw1: UIImageVIEw! @IBOutlet weak var imageVIEw2: UIImageVIEw! var imagePicker = UIImagePickerController() var imagePicked = 0 overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() imagePicker.delegate = self imagePicker.sourceType = .savedPhotosAlbum imagePicker.allowsEditing = false } @IBAction func chooseImage1(_ sender: UIbutton) { if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.savedPhotosAlbum){ imagePicked = sender.tag present(imagePicker,animated: true) } } func imagePickerController(_ picker: UIImagePickerController,dIDFinishPickingMediawithInfo info: [String : Any]) { let pickedImage = info[UIImagePickerControllerOriginalimage] as? UIImage if imagePicked == 1 { imageVIEw1.image = pickedImage } else if imagePicked == 2 { imageVIEw2.image = pickedImage } dismiss(animated: true) } func imagePickerControllerDIDCancel(_ picker: UIImagePickerController) { dismiss(animated: true) }}总结
以上是内存溢出为你收集整理的ios – 使用Swift中的imagePickerController在同一视图控制器中拾取两个不同的图像全部内容,希望文章能够帮你解决ios – 使用Swift中的imagePickerController在同一视图控制器中拾取两个不同的图像所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)