2

i'm using UIImagePickerControllerSourceTypeCamera in my app, but a want to add the camera view a subview. not as modal view.

now i'm using

UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
[self presentModalViewController:picker animated:YES];   

i want to use it like this, but doesn't seem to work ..

UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
[picker.view setFrame:CGRectMake(300, 40, 300, 200)];
[self.view addSubview:picker.view];

i know that the UIImagePickerControllerSourceTypeCamera only can be used as modal view. How is for example Hipstamatic using this for example?

1
  • I assume Hipstamatic is using modal UIImagePickerController (without controls), but overlay it with own custom views. May 6, 2011 at 19:21

3 Answers 3

10

This is possible in iOS 4+ using the AVCaptureSession framework. It's much more complicated than using UIImagePickerController, but you have complete control over input and output. The key to having the camera view as a subview is the following code. Assume you have a subview called previewView that you want to show the camera view:

AVCaptureSession *session = [[AVCaptureSession alloc] init];
AVCaptureVideoPreviewLayer *previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:session];
previewLayer.frame = self.previewView.bounds; 
[self.previewView.layer addSublayer:previewLayer];

There is more setup work to do to give your AVCaptureSession object the correct input and output devices and to actually capture the photos. That can be found in the documentation and examples on the web.

0

You're right, the only supported methods for displaying a UIImagePickerController seem to be presentModalViewController:animated: or UIPopoverController.

I'm not familiar with Hipstamatic, but chances are it is using AVFoundation, in particular AVCaptureVideoPreviewLayer.

1
  • "Available in iOS 4.0 and later." I've never used Hipstamatic, but I think it's older than iOS 4.0.
    – Erik B
    May 6, 2011 at 19:27
0

Visit link to get idea how things can be accomplished. Look out for AVCam Demo in developer.apple.com resources for IOS programme. You will definitely get idea how it works. You should be registered developer with APPLE, and thats very easy.

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.