0

I would like to create a ViewController, and when the user loads it, he's automatically redirected to camera. I know how to go in camera when the user press a button, but not when he doesn't do anything. For example, when you load snapchat app, you're automatically in the camera to take a picture, I would like to perform that.

Any ideas ? Thank's

mgul
  • 742
  • 8
  • 27

1 Answers1

1

Just insert your code in the method of viewDidLoad. What that does is, as soon as the view loaded, whatever is in that method gets called.

Take a look at this page: UIViewController Class Reference

Jessica
  • 9,379
  • 14
  • 65
  • 136
  • Just before testing, do you think I should go in Objective-C ? I want to customize the camera (add buttons, add a picture filter fonction...), and I saw the only one module which permits that is only available on O-C... – mgul Aug 19 '15 at 17:27
  • Well, you can use both if you want. Here is a video tutorial of adding a picture filter: http://www.swiftvideotutorials.com/core-image-filters-on-ios – Jessica Aug 19 '15 at 17:31
  • Thank you for your answer. I think i'll stay in swift. I follow this tutorial : http://www.ioscreator.com/tutorials/take-photo-tutorial-ios8-swift which permit me to access camera when I press on a button. You told me to put it in `viewDidLoad`, but how ? Should I call the `takePhoto()` function in the `viewDidLoad()` function ? – mgul Aug 19 '15 at 18:13
  • Ok I just tested it by myself and it works. Thank's very much ! here's my code: `class ViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate { @IBOutlet var pictureImageView: UIImageView! var imagePicker: UIImagePickerController! override func viewDidLoad() { super.viewDidLoad() imagePicker = UIImagePickerController() imagePicker.delegate = self imagePicker.sourceType = .Camera presentViewController(imagePicker, animated: true, completion: nil) } }` – mgul Aug 19 '15 at 18:18
  • Glad to hear it works! – Jessica Aug 19 '15 at 18:37
  • Swift 4.2 imagePicker = UIImagePickerController() imagePicker.delegate = self imagePicker.sourceType = .camera present(imagePicker, animated: true, completion: nil) – Imtee Feb 14 '19 at 01:07