[英]Swift/XCode - Select ANOTHER using ImagePickerController
我想知道如何使用ImagePickerController
选择多个图像。
但是,我不希望在ImagePickerController
控制器中选择多个图像。 相反,当用户选择我的应用程序设置imageView
(他们都有一个tapGestureRecogniser
)。 有10个。因此,每当用户点击某个imageView
,我都希望将图像应用于所选的imageView
。
但是,它始终覆盖第一个imageView
。
我该如何解决?
编辑 - -
因此,想象一下这些是我的imageViews:
[1] [2] [3] [4] [5]
我点击第三个,然后选择一张图像。 然后应将图像应用于第三个imageView。 然后,我可以决定选择第一个imageView并添加另一个图像等。
我希望这是有道理的。
编辑x 2-我的代码:
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.handleSelectedImage))
selectedImage.addGestureRecognizer(tapGesture)
selectedImage.isUserInteractionEnabled = true
func handleSelectedImage() {
let pickerController = UIImagePickerController()
pickerController.delegate = self
pickerController.mediaTypes = ["public.image", "public.movie"]
pickerController.allowsEditing = true
pickerController.modalPresentationStyle = .popover
pickerController.popoverPresentationController?.delegate = self as! UIPopoverPresentationControllerDelegate
pickerController.popoverPresentationController?.sourceView = selectedImage
let alertController = UIAlertController(title: "Add a Picture", message: "Choose From", preferredStyle: .actionSheet)
let cameraAction = UIAlertAction(title: "Camera", style: .default) { (action) in
pickerController.sourceType = .camera
self.present(pickerController, animated: true, completion: nil)
}
let photosLibraryAction = UIAlertAction(title: "Photos Library", style: .default) { (action) in
pickerController.sourceType = .photoLibrary
self.present(pickerController, animated: true, completion: nil)
}
let savedPhotosAction = UIAlertAction(title: "Saved Photos Album", style: .default) { (action) in
pickerController.sourceType = .savedPhotosAlbum
self.present(pickerController, animated: true, completion: nil)
}
let videoAction = UIAlertAction(title: "Videos", style: .default) { (action) in
pickerController.mediaTypes = ["public.movie"]
pickerController.sourceType = .photoLibrary
self.present(pickerController, animated: true, completion: nil)
}
let cancelAction = UIAlertAction(title: "Cancel", style: .destructive, handler: nil)
alertController.addAction(cameraAction)
alertController.addAction(photosLibraryAction)
alertController.addAction(savedPhotosAction)
alertController.addAction(videoAction)
alertController.addAction(cancelAction)
present(alertController, animated: true, completion: nil)
}
func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
return .none
}
extension AddPostViewController: UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIPopoverPresentationControllerDelegate {
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let image = info["UIImagePickerControllerOriginalImage"] as? UIImage {
chosenImage = image
selectedImage.image = image
dismiss(animated: true, completion: {
self.performSegue(withIdentifier: "returnHome", sender: nil)
})
}
}
您可以做的是使用imageView的tag属性以及一个变量来记录哪个imageView进行了调用。 下面提到的是一个粗略的轮廓。
selectedImageView
) imageView
进行调用打开imagePickerController
,设置selectedImageView = imageView.tag
selectedImageView
的值并将该图像设置为具有相同标签的imageView
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.