0
import UIKit

class DrawingTransistionViewController: UIViewController,
    UIImagePickerControllerDelegate,
    UINavigationControllerDelegate
{
    override func viewWillAppear(_ animated: Bool)
    {
        let imagePicker = UIImagePickerController()

        imagePicker.delegate = self
        imagePicker.sourceType = .camera

        self.present(imagePicker, animated: true, completion: nil)
    }
}

Currently when the code runs, it opens the camera but when you exit the camera the camera opens again because the view appears again. So I'm stuck in a constant loop. I want the camera to only open once when transitioning between the view. I've already tried viewWillDisappear(), viewDidAppear, and viewDidDisappear() but haven't had any success.

This is the only helpful documentation that I've been able to find but haven't had much luck with it. https://developer.apple.com/reference/uikit/uiviewcontroller#//apple_ref/doc/uid/TP40006926-CH3-SW18

Any ideas?

Thanks

1 Answers1

0

I did not fully understand your question. Uglu solution is to just put boolen isCameraOpen and before opening camera just aks is open, first time you open just set that bool to true. Why are you not using viewDidLoad?

Markicevic
  • 1,025
  • 9
  • 20
  • Do not use `viewDidLoad`. – rmaddy Dec 13 '16 at 00:07
  • Can you please write why? Not saying you are wrong i just want to know why is that bad. Never had to do it myself it was just prepostion. – Markicevic Dec 13 '16 at 00:11
  • I've tried viewDidLoad but it doesn't work. I can't tell you why. I'd like to know why not to use viewDidLoad too. – Cornelius N. Dec 13 '16 at 00:16
  • Did solution in duplicated question work for you, i did not have idea that this was happening, it is awesome that i learned that now :D – Markicevic Dec 13 '16 at 00:18
  • Thanks for the help and link. I solved the issue because of you guys! – Cornelius N. Dec 13 '16 at 00:20
  • `viewDidLoad` is too soon to present another controller from the loading controller because the loading controller isn't added to the window yet and you will likely get an error about "presenting a controller from a controller not currently in the window hierarchy". – rmaddy Dec 13 '16 at 00:26