I have a requirement in my app where i have to open iphone camera from my app with preview option at bottom(shown in attached image) like how it is in iphone camera app.
Can someone please guide me on how to achieve this.
Thanks
Varun
Create a UIImagePickerController from code, adjust its properties, add an overlay onto it, and with you controller, control whatever you want on that overlay : custom controls, overlaying images, etc.
That gives something like this :
self.picker = [[UIImagePickerController alloc] init];
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
self.picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
self.picker.showsCameraControls = NO;
self.picker.navigationBarHidden = YES;
self.picker.toolbarHidden = YES;
self.picker.wantsFullScreenLayout = YES;
// Insert the overlay
self.overlay = [[OverlayViewController alloc] initWithNibName:#"Overlay" bundle:nil];
self.overlay.pickerReference = self.picker;
self.picker.cameraOverlayView = self.overlay.view;
self.picker.delegate = self.overlay;
[self presentModalViewController:self.picker animated:NO];
OverlayViewController is the controller that you must write to control everything you add onto the overlay.
pickerReference is a property you can keep to send orders to the camera. For example, you could call the following from an IBAction coming from a UIButton placed onto the overlay :
[self.pickerReference takePicture];
you see this link for example https://github.com/anka/bw_examples
Related
I have tried a couple of different methods for presenting a landscape-oriented UIImagePickerController in a landscape-only app (not by my choice) I'm working on.
When I (successfully) present the gallery in landscape format and scroll through the images, there is a truly horrible stutter!
The current technique I am using is this:
- (void)presentImagePickerController:(UIImagePickerControllerSourceType)sourceType {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
if (isDeviceIPad) {
picker.modalPresentationStyle = UIModalPresentationFormSheet;
picker.preferredContentSize = [UIScreen mainScreen].bounds.size;
}
picker.sourceType = sourceType;
picker.delegate = self;
picker.allowsEditing = YES;
[self presentViewController:picker
animated:YES
completion:nil];
}
I cannot go with a solution which uses private interfaces, since the app has to pass App Store review. I'd prefer not to use a third-party library, since my boss is against that idea.
My iPad is a 3rd generation, model MD334LL/A that's running iOS 8.1.
From the UIImagePickerController class reference found here: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImagePickerController_Class/index.html
On iPad, the correct way to present an image picker depends on its source type, as summarized in this table:
Camera: Use full screen
Photo Library: Must use a popover
Saved Photos Album: Must use a popover
Answer: Since I want to present the Saved Photos Album, I need to present the picker by using a popover.
- (void)presentImagePickerController:(UIImagePickerControllerSourceType)sourceType {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = sourceType;
picker.delegate = self;
picker.allowsEditing = YES;
if (isDeviceIPad() && sourceType == UIImagePickerControllerSourceTypeSavedPhotosAlbum) {
picker.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *presentationController = picker.popoverPresentationController;
presentationController.permittedArrowDirections = UIPopoverArrowDirectionAny;
presentationController.sourceView = self.presentPickerButton;
presentationController.sourceRect = self.presentPickerButton.bounds;
}
[self presentViewController:picker
animated:YES
completion:nil];
}
I am using an UIImagePickerController with sourceType = UIImagePickerControllerSourceTypeCamera;
However I want to specify that I want to take only photos, not videos , (in a native camera user can switch to video) is there a way to do so ?
Here is the code I am using :
if (([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera] == NO))
return ;
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 = self;
[self presentViewController:cameraUI animated:YES completion:nil];
My 1st guess was is to change the sourceType = UIImagePickerControllerSourceTypeCamera; but the other options are galleries options.
My 2nd guess is: to change the array of mediaTypes but I don't know to which 1
https://developer.apple.com/library/ios/documentation/uikit/reference/uiimagepickercontroller_class/index.html#//apple_ref/c/tdef/UIImagePickerControllerCameraCaptureMode
cameraUI.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
I have an iPad app that only supports landscape orientations, however when I try to display a UIImagePickerController inside a UIPopoverController it always appears in portrait mode. i.e. rotated 90 degrees from the rest of the UI. Does anyone know how I can make this appear in the same orientation as the ViewController I'm presenting it in?
I'm displaying the imagePicker like this:
self.picker = [[FFSImagePicker alloc] init];
picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];
picker.delegate = self;
picker.toolbarHidden = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.allowsEditing = NO;
picker.showsCameraControls = YES;
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:picker];
self.photoPickerPopover = popover;
[self.photoPickerPopover presentPopoverFromRect:photoButton.bounds inView:photoButton permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];
FFSImagePicker is just a subclass of UIImagePickerController where I tried to make sure the supported orientations were only landscape, but that had no effect.
Thanks for any help...
OK, I solved this, the issue was that I was presenting the UIImagePickerController in a UIPopover which Apple says not to do when the source type is the camera, instead present it full screen just like you would any other view controller.
Hope this helps someone else too...
I am using an imagePicker with a custom overylay view, which has a button for the photo library, among other things. I am instantiating it like this:
_overlay = [[CameraWithOverlayViewController alloc]initWithNibName:#"OverlayView" bundle:nil];
_overlay.delegate = self;
_imagePicker = [[UIImagePickerController alloc] init];
_imagePicker.delegate = self;
_imagePicker.allowsEditing = NO;
_imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
_imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
_imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
_imagePicker.modalPresentationStyle = UIModalPresentationCurrentContext;
_imagePicker.showsCameraControls = NO;
_imagePicker.navigationBarHidden = YES;
_imagePicker.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;
_imagePicker.cameraOverlayView = _overlay.view;
and presenting modally. The CameraWithOverlayViewController reports overlay button presses back to me via a delegate protocol, which I then use to take the photo, switch to the photo library, or cancel out of the imagePicker.
When the user clicks the photo library button, I am running this:
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
to bring up the photo library instead of the camera.
Problem one is that when you use a custom camera overlay view, the imagePicker.allowsEditing boolean property is bypassed, which means I had to build my own cropping view. But the photo library is sending me to the cropping view even with imagePicker.allowsEditing = NO set.
The second problem is that, despite having set myself as the imagePicker's delegate, and implementing the delegate protocol/methods, the cancel button on the photo library's view is not calling - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker, so I cannot use that method to put a user back on the camera screen if they cancel from the photo library.
Any insight would be much appreciated!
I have used Image Picker Controller to call device camera. The code listed below works fine below iOS 7. But when I use the Same code on iOS 7 to launch camera I am unable see "Use" and "Cancel" buttons.
- (void)getCameraPicture {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = NO;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
[self presentViewController:picker animated:YES completion:NULL];
}
Any help is appreciated.
Update:
When I try to run this code in a sample app then it works fine.(sample app contains single view). But when I put it inside my project the buttons doesn't show.
in the code should be there:
...
picker.showsCameraControls = YES;
have you checked this #property (nonatomic) BOOL showsCameraControls in UIImagePickerController.