I am currently creating a simple app in Swift for an iPhone. When the I press the button "Take Photo" the camera opens up, so I can take a picture. Then when I press "Use Photo", it just stays on the first screen with the "Take Photo" button. How do I get the app to show the next screen/storyboard after pressing "Use Photo"?
Asked
Active
Viewed 772 times
1
-
You need to dismiss the image picker – Leo Dabus Jun 09 '20 at 22:26
2 Answers
0
On your home screen there are two buttons...
1. Take Photo
2. Use Photo
So when you click on Take photo, it opens camera & you're able to capture photo alright.
Now when you're on home screen, when you press Use Photo
button, it doesn't go to image library right.
So from this, scenario onwards, I'll provide you solution to use photo.
Solution : Please go through this, here I'm using image-picker on button click. It will allow you to select/choose image and assign your selected image to a UIImageView
.
import UIKit
class ViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
@IBOutlet weak var imageView: UIImageView!
@IBAction func btnUsePhoto(_ sender: Any) {
let imagePicker = UIImagePickerController()
if UIImagePickerController .isSourceTypeAvailable(UIImagePickerController.SourceType.photoLibrary)
{
imagePicker.sourceType = UIImagePickerController.SourceType.photoLibrary
imagePicker.allowsEditing = true
imagePicker.delegate = self
self .present(imagePicker, animated: true , completion: nil)
}
}
override func viewDidLoad() {
super.viewDidLoad()
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if let pickerImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
self.imageView.contentMode = .scaleAspectFit
self.imageView.image = pickerImage
dismiss(animated: true)
}
}
}
I hope, it will solve your issue.

Ashish Langhe
- 421
- 1
- 5
- 15
0
Probably your answer is here:
It's a copy&paste solution for taking images. I just did a few little changes.
Don't forget to set the right orientation of the picture when taking landscape picture:

de.
- 7,068
- 3
- 40
- 69

FrugalResolution
- 568
- 4
- 18