0

I would like a moving image--live camera--to be visible as soon as a screen loads--similar to Snapchat. In Snapchat's case, the image fills the whole screen. I would just like it to be visible in a portion of the screen in a UIView for example. Can I accomplish this with UIImagePickerView or must I use AV Foundation?

My question is how to have the camera on in preview when the screen loads as other questions address the front vs. rear facing choice.

Right now, I have a placeholder image that if clicked launches a UIImagePickerController. Relative to having the image on, this requires the extra step of clicking to launch the UIImagePicker Controller.

As this is is for a profile pic, ideally, the user would see an image of their face as soon as the screen loads and merely need to click to capture an image.

Can this be done with UIImagePickerController or do you need to use AVFoundation?

Here is my current UIImagepickerController code but it merely presents a new VC after you take an action rather than displaying a live image by default.

- (IBAction)takePhoto:(UIButton *)sender {
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;

    [self presentViewController:picker animated:YES completion:NULL];

}
user6631314
  • 1,751
  • 1
  • 13
  • 44
  • Possible duplicate of [UIImagePickerController - How do I access the front facing camera by default?](https://stackoverflow.com/questions/8950011/uiimagepickercontroller-how-do-i-access-the-front-facing-camera-by-default) – DonMag Mar 02 '18 at 15:32
  • that question seems to be about front vs. rear facing. My question is how to have camera live and on when screen loads. Can this be done with impagepicker or do you need to use AVFoundation? – user6631314 Mar 02 '18 at 16:07
  • As indicated in the answer to that question, I added the line `picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;` to your code (after the `.sourceType =` line) and the front-facing camera was live. Isn't that what you are trying to do? – DonMag Mar 02 '18 at 16:12
  • Or are you asking how to "auto-launch" the picker with the camera active, instead of in response to a button tap? – DonMag Mar 02 '18 at 16:13
  • My original code above launches a pickerview controller ie a new VC and the image is live. What I would like to do instead is have a live preview in a UIView similar to snapchat. In otherwords, you see live picture as soon as screen loads instead of placeholder image that you must click on. I will try to make this clearer in question. – user6631314 Mar 02 '18 at 16:21
  • 1
    I don't use snapchat... but if I understand your question now, you're asking if you can make the camera view a *subview* of another view? If so, then no, you cannot do that with `UIImagePickerController` - you'd need to use `AVFoundation`. – DonMag Mar 02 '18 at 16:28
  • Yes basically, I want the live image to appear in a regular View controller as opposed to a presented UIImagePickerController. So I need to use AVFoundation to do this? – user6631314 Mar 02 '18 at 16:31
  • Yes - Apple has a sample app that should give you everything you need: https://developer.apple.com/library/content/samplecode/AVCam/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010112 – DonMag Mar 02 '18 at 16:35
  • Ok. Thanks for straightening this out. – user6631314 Mar 02 '18 at 16:39

0 Answers0