I have 1 UIImageView, user can tap on UIImageView to select photo from photo library,
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(cameraTapped(tapGestureRecognizer:))) cameraUIView.isUserInteractionEnabled = true cameraUIView.addGestureRecognizer(tapGestureRecognizer) where cameraTapped is
func cameraTapped(tapGestureRecognizer: UITapGestureRecognizer) { let imagePicker = UIImagePickerController() imagePicker.delegate = self let actionSheet = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) actionSheet.addAction(UIAlertAction(title: "写真を撮る", style: .default, handler: { (action:UIAlertAction) in if UIImagePickerController.isSourceTypeAvailable(.camera) { imagePicker.sourceType = .camera imagePicker.allowsEditing = true self.present(imagePicker,animated: true,completion: nil) } })) actionSheet.addAction(UIAlertAction(title: "アルバムから選択する", style: .default, handler: { (action:UIAlertAction) in if UIImagePickerController.isSourceTypeAvailable(.photoLibrary) { imagePicker.sourceType = .photoLibrary self.present(imagePicker,animated: true,completion: nil) } })) actionSheet.addAction(UIAlertAction(title: "キャンセル", style: .cancel, handler: nil)) self.present(actionSheet, animated: true, completion: nil) and
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { if let image = info[UIImagePickerControllerOriginalImage] as? UIImage { selectedImage = image cameraUIImageView.image = image cameraUIImageView.contentMode = .scaleAspectFill cameraUIImageView.clipsToBounds = true let leadingConstrain = NSLayoutConstraint(item: cameraUIImageView, attribute: .leading, relatedBy: .equal, toItem: cameraUIImageView.superview, attribute: .leading, multiplier: 1, constant: 0) leadingConstrain.isActive = true let trailingConstrain = NSLayoutConstraint(item: cameraUIImageView, attribute: .trailing, relatedBy: .equal, toItem: cameraUIImageView.superview, attribute: .trailing, multiplier: 1, constant: 0) trailingConstrain.isActive = true let topConstrain = NSLayoutConstraint(item: cameraUIImageView, attribute: .top, relatedBy: .equal, toItem: cameraUIImageView.superview, attribute: .top, multiplier: 1, constant: 0) topConstrain.isActive = true let bottomConstrain = NSLayoutConstraint(item: cameraUIImageView, attribute: .bottom, relatedBy: .equal, toItem: cameraUIImageView.superview, attribute: .bottom, multiplier: 1, constant: 0) bottomConstrain.isActive = true } dismiss(animated: true, completion: nil) cameraLabel.text = "" } This works. However, I want to have 3 UIImageView, tap on each of UIImageView will let user select photo and display that photo on UIImageVIew.
Do I need to create 3 different imagePickerController? And how to do that?, because imagePickerController the implementation of UIImagePickerDelegate.
