I have a UIImagePickerController that is presented as a modal view controller. This works fine, except for when I try to add anything to the camera overlay view.
As soon as I modify the camera overlay view, the default zoom control stops working (although tap to focus still works). If I tap on the view, the zoom slider appears, but I am not able to slide it up and down like usual.
Here's the code I'm using:
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.allowsEditing = NO;
imagePickerController.delegate = self;
imagePickerController.showsCameraControls = YES;
imagePickerController.wantsFullScreenLayout = NO;
[imagePickerController.cameraOverlayView addSubview:overlayView];
[self presentModalViewController:imagePickerController animated:YES];
Has anyone had a similar problem or can see what I'm doing wrong? I know it should work, as I've seen it on other apps that also use the default camera controls.
Thanks :)
After a lot of mucking round I've finally come across a solution. Don't use the cameraOverlayView property, instead add a subview to the UIImagePickerController with a frame of size CGRectZero.
In the following example, overlayView is a custom subclass of UIView which draws an image and passes touches through to the next responder:
OverlayView *overlayView = [[OverlayView alloc] initWithFrame:CGRectZero];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.allowsEditing = NO;
imagePickerController.delegate = self;
imagePickerController.showsCameraControls = YES;
[imagePickerController.view addSubview:overlayView];
statViewController.imagePickerController = imagePickerController;
}
-
And then, everything just works. Not sure if adding a subview to UIImagePickerController is documented and ok with Apple, but heaps of other apps use this (or a similar workaround) so shouldn't cause any submission problems.
Related
i'm using the UIImagePickerController to show the camera view in my main view, calling it with this code:
self.picker = [[UIImagePickerController alloc] init];
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
self.picker.showsCameraControls = NO;
and i have a self made toolbar in my storyboard, to manage some camera's functionality.
What happens is that when the app loads, the camera seems to overlay my toolbar, going in fullscreen and hiding my buttons. Why this happens?
It's normal the UIImagePickerController is ment to run full screen. You can an extra overlay view to the cameraOverlayView property to show you own controls.
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?
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.
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.
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.
Is it possible to pop the camera (using UIImagePickerControllerSourceTypeCamera) on the iPad 2 inside of a UIPopoverController using presentModalViewController?
Whenever I do it the camera just goes full screen. I need it inside of the UIPopoverController.
This won't work by calling presentModalViewController:animated:. To make the camera show up in a UIPopoverController's UI, then you want something similar to the following:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.allowsEditing = YES;
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
UIPopoverController *popover = [[UIPopoverController alloc]
initWithContentViewController:imagePicker];
[popover presentPopoverFromBarButtonItem:launchCameraButton
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
There is another way to launch the popover from an arbitrary spot in your UI also. The docs should explain that.
I'm just playing around with a simple program that opens the camera. That's literally all that I want to do. I'm a beginner and I believe that I have the basics down in terms of UI management for the iPhone so I decided to give this one a whirl.
What I'm trying to do right now is...
- (BOOL) application:(UIApplication*) application didFinishLaunchingWithOptions:(NSDictionary*) launchOptions
{
UIImagePickerController * camera = [[UIImagePickerController alloc] init];
camera.delegate = self;
camera.sourceType = UIImagePickerControllerSourceTypeCamera;
camera.allowsEditing = NO;
camera.showsCameraControls = NO;
[viewController presentModalViewController:camera animated:NO];
[window addSubview:viewController.view];
[window makeKeyAndVisible];
return YES:
}
So basically, initialize the camera, set some things and show it in the main view. I set the camera's delegate to self because this code is placed in the delegate class (and yes, the delegate class is conforming to UIImagePickerControllerDelegate && UINavigationControllerDelegate).
Main problem right now is that nothing is appearing on the screen. I have absolutely no idea what I'm doing wrong, especially since the program is building correctly with no errors or warnings...
Any help is appreciated! Thanks a lot :D
You are trying to display the UIImagePickerController from your view controller before you'e added its view to the window. That won't work. It has to be presented from a view that is already displaying.
I'm not absolutely sure this will work as I haven't tried it, but switch the order of your code. Add your view controller to the window first:
- (BOOL) application:(UIApplication*) application
didFinishLaunchingWithOptions:(NSDictionary*) launchOptions
{
[window addSubview:viewController.view];
[window makeKeyAndVisible];
UIImagePickerController * camera = [[UIImagePickerController alloc] init];
camera.delegate = self;
camera.sourceType = UIImagePickerControllerSourceTypeCamera;
camera.allowsEditing = NO;
camera.showsCameraControls = NO;
[viewController presentModalViewController:camera animated:NO];
return YES:
}
If this doesn't work, then try moving your UIImagePickerController code to your -viewDidLoad of your root view controller (whatever viewController is in your code).
I have troubles using UIImagePicker to take pictures based on the "Taking Pictures with the Camera" chapter from the iPhone programming guide.
Whatever i try all i get is a grey/white screen.
here is my code :
- (void)viewDidLoad {
[super viewDidLoad];
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.allowsEditing = NO;
[self presentModalViewController:imagePicker animated:YES];
}
I've tried to call the imagePicker from the viewDidLoad, viewWillAppear or awakeFromNib, nothing changes.
My viewController implements UINavigationControllerDelegate and UIImagePickerControllerDelegate.
I'm running this on OS3.1 on a first gen iPhone.
Any help would be greatly appreciated !
Thanks,
Vincent.
I would placing that call in viewDidAppear as oposed to viewDidLoad.