My iPhone app allows the user to record videos.
How can I customize my camera view like in the screen shots.(also I need to make a custom timer-countDown)
You need to put all the custom elements in a UIView and assign that view to the cameraOverlayView property.
- (void)takePicture {
if (([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera] == NO)) return;
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
// add a custom view overlay
[imagePickerController setCameraOverlayView:customView];
[self presentModalViewController:imagePickerController animated:YES];
[imagePickerController release];
}
See also http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html#//apple_ref/occ/instm/UIImagePickerController/cameraOverlayView
Related
I am trying to display a UIImagePicker from a programatically generated UIView that's added as a subview of the original view controller. The image picker comes up and so does the camera but the functionality breaks and nothing navigates properly. How do I properly load an image picker from a UIView and not a UIControlView?
code that breaks:
- (void)captureImage:(id)sender
{
[[[UIActionSheet alloc] initWithTitle:nil
delegate:self
cancelButtonTitle:#"Close"
destructiveButtonTitle:nil
otherButtonTitles:#"Take photo", #"Camera Roll", nil]
showInView:self];
}
//UIImagePicker specific methods
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch (buttonIndex)
{
case 0:
[self takePhoto];
break;
case 1:
[self fromCameraRoll];
break;
}
}
-(void)takePhoto
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == YES)
{
// Create image picker controller
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
// Set source to the camera
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
// Delegate is self
imagePicker.delegate = self;
// Show image picker
[self addSubview:imagePicker.view];
}
}
-(void)fromCameraRoll
{
UIImagePickerController *imgPicker = [[UIImagePickerController alloc] init];
imgPicker.delegate = self;
imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self addSubview:imgPicker.view];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Access the uncropped image from info dictionary
UIImage *image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
//do something with the image
//add code to pick images here and store them in the preview
[picker dismissModalViewControllerAnimated:NO];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissModalViewControllerAnimated:NO];
}
UIImagePickerController is view controller class, you better present your image picker to your parent view controller by a delegate call or something like with an overlay subview to achieve your goal.
UIImagePickerController *imgPicker = [[UIImagePickerController alloc] init];
imgPicker.delegate = self;
imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
CustomOverlayView *overlayview = [[CustomOverlayView alloc] init];
imgPicker.cameraOverlayView = overlayview;
[self presentModelViewController:imgPicker animated:YES];
add another delegate in your overlay class to dismiss your camera picker controller view
[imgPicker dismissModelViewControllerAnimated:YES];
I am developing an app in which i need to keep open full screen camera open and also add a button on it(bottom right). I googled but couldn't find any healthy solution. Thanks in advance. Have a good day.
Edited
- (void) showCameraUI {
[self startCameraControllerFromViewController: self
usingDelegate: self];
}
- (BOOL) startCameraControllerFromViewController: (UIViewController*) controller
usingDelegate: (id <UIImagePickerControllerDelegate,
UINavigationControllerDelegate>) delegate {
if (([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera] == NO)
|| (delegate == nil)
|| (controller == nil))
return NO;
NSLog(#"Start Camera Controller method...");
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
// Displays a control that allows the user to choose picture or
// movie capture, if both are available:
cameraUI.mediaTypes =
[UIImagePickerController availableMediaTypesForSourceType:
UIImagePickerControllerSourceTypeCamera];
// Hides the controls for moving & scaling pictures, or for
// trimming movies. To instead show the controls, use YES.
cameraUI.allowsEditing = NO;
cameraUI.delegate = delegate;
[controller presentModalViewController: cameraUI animated: YES];
return YES;
}
P.S: I also added UINavigationControllerDelegate,UIImagePickerControllerDelegate as protocol in header file, but its not still opening camera and show me default view of project.
you can simply capture image Using camera like bellow, i am using this bellow method in my code:-
-(void)btnCemeraOpen
{
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
}
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissModalViewControllerAnimated:YES];
yourImageView.image = [info valueForKey:#"UIImagePickerControllerOriginalImage"];
if(yourImageView==nil)
{
}
else
{
//DO logic
}
return;
}
All
I have create UIImagePickerController with delegate and picking images from PhotoLibrary.
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
[self presentModalViewController:imagePicker animated:YES];
And when application reach to Editing view of UIImagePickerController i set one Overlay view and create two buttons for it.
Cancel and Choose
On Cancel Button click
[imagePicker popToViewController:[currentViewController.viewControllers objectAtIndex:1] animated:YES];
this cod work fine..
But choose Button does not working,
if i set code like here,
[self imagePickerController:imagePicker didFinishPickingMediaWithInfo:[imagePicker mediaTypes]];
than it returns NULL value of info dictionary.
Is that any other way to set overlay view on Editing ImagePicker ?
Regards,
try this code
CustomOverlayView *CustomOverlayView = [[CustomOverlayView 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:CustomOverlayView];
[self presentModalViewController:imagePickerController animated:YES];
}
I am developing an Augmented Reality app for iPhone with ARToolkit. Now I want to include its functionality in a main app, with a button which throws an 'AR View', in order to be able to take a picture with the 3D model on it.
I am using UIImagePickerController with cameraOverlayView to add the ARViewController view to the camera view, as an overlay, but it does not show it. Here it is the code:
-(IBAction)Switch2AR:(id)sender{
ARController = [[ARViewController alloc] init];
[ARController loadView];
UIImagePickerController *picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
else {
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
picker.showsCameraControls = YES;
picker.cameraOverlayView = ARController.view;
//[ARController.view addSubview: picker.view];
//[picker.view addSubview: ARController.view];
//[picker viewWillAppear:YES];
//[picker viewDidAppear:YES];
//[ARController viewWillAppear:YES];
//[ARController viewDidAppear:YES];
[self presentModalViewController:picker animated:YES];
[ARController release];
}
I also tried to add the UIImagePickerController view as a subview of the ARViewController view, but does not work since the camera modal view 'hides' the AR view. Also ARViewController view as UIImagePickerController subview.
The problem is that I cannot overlay my ARView and the camera view in any way I tried
Thanks in advance
Just change
picker.showsCameraControls = YES;
to
picker.showsCameraControls = NO;
and it should work.
The new 3.1 sdk allows for the UIImagepickerController to hide the camera controls and use your own controls via cameraOverlay view. So, I implemented the overlay view through another Viewcontroller:
CameraViewController *cameraController = [[CameraViewController alloc] initWithNibName:#"CameraViewController" bundle:nil];
self.cameraviewController = cameraController;
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.cameraOverlayView = cameraviewController.view;
picker.showsCameraControls = NO;
[self presentModalViewController:picker animated:YES];
[cameraController release];
[picker release];
The cameraviewController.view has the Cancel button. The problem I'm facing is how to dismiss the Modal view with that cancel button. I haven't found a way of referencing the controller which called the Modalview.
Many thanks in advance
need to add cameraController.delegate = self; and setup the delegate protocol in CameraViewController.