views:

873

answers:

4

I've been working pretty extensively the last couple months with UIImagePickerController, particularly with the new capabilities in OS3.1 and newer to overlay views on-top of the camera view. This has worked just fine.

However, I am currently working on a project where I'd like to be able to display the camera view of the UIImagePickerController within an existing view. Essentially, the exact opposite of what I've currently been doing.

An example would be a View Controller with navigation components (Think top and bottom horizontal bars with gradients), and upon tapping a button on one of these bars, then content area displays the camera view. The shutter animation would should up, and the top and bottom navigation bars would remain always on-top.

I've had success adding the UIImagePickerController to the window view, as well as presenting it modally, but haven't had any luck adding it as a subView.

ex:

[window addSubview:camera.view];
[self presentModalViewController:camera animated:YES];
A: 

I don't think the API provides direct access to the actual view of the UIImagePickerController. The class is actually a subclass of UINavigationController so I don't think it has an actual view itself but rather manages the calling of its subcontrollers and their views.

When you call the UIImagePickerController modally, its doesn't add the views it controls as subviews to the window (or any other view). That is what a modal view means. It presents the view off to the "side" of the view hierarchy.

Even if you could hack this together, I think Apple would reject it as not being part of the API and for violating the HIG.

TechZen
+1  A: 

Call viewWillAppear:YES on the image picker controller after adding its view to your view. Skip the modal view controller business.

Jim
Just tried this and the camera view displays, but the lens doesn't open. It just stays stuck on that graphic with the lens closed. Not sure if this is still a related issue or not.Here's what I did: [self.view addSubview:camera.view]; [camera viewWillAppear:YES];
u2elan
A: 

I called the viewWillAppear:YES as well and the same thing that happened to u2elan happened to me. The graphic with the closed lens, and doesn't open. what to do?

A: 

All you need to do is call viewWillAppear and viewDidAppear.

Here is an example where _pickerController is an instance of UIImagePickerController:

[self.view addSubview:_pickerController.view];
[_pickerController viewWillAppear:YES];
[_pickerController viewDidAppear:YES];
Jason