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;
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 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
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!
When a user clicks a certain button,I want him to have the ability to choose between taking a picture and choosing a picture from a gallery. As of right now it seems to be one or the other. Should I create two buttons for this or is there a better what to accomplish this? I am hoping a way to click a button and iOS will natively give the user the choice.
-(IBAction)takePhoto:(id)sender
{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
// image picker needs a delegate,
[imagePickerController setDelegate:self];
// Place image picker on the screen
[self presentModalViewController:imagePickerController animated:YES];
}
In my opinion the best way would be to Create for example 2 buttons
UIBarButtonItem * choosePhotoBtn
UIBarButtonItem * TakePhotoBtn
Then call the same IBAction when pressing either button, and put a condition in it to call the appropriate interface somehting like this:
-(IBAction) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if((UIBarButtonItem *) sender == choosePhotoBtn) {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
} else {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentViewController:picker animated:YES completion:nil];
}
But these are the best options, I like the UIAlertView the most to be honest
To be honest thats more clicks for the user, but again thats my opinion .
Here's how you can do it, Create your UIAlertView , then put a condition in its deleguate method:
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSString *BtnSelected = [alertView buttonTitleAtIndex:buttonIndex];
if([BtnSelected isEqualToString:#"choosePhotoBtn"] {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
} else {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentViewController:picker animated:YES completion:nil];
}
When user press the button you can display UIAlertView or UIActionSheet, I would recommended UIAlertView for two button. And in the delegate method base on user selection you can make your logic to access camera or gallery.
There are two options -
First show the pickerController with source type as photo library. Then there is a property in UIImagePickerController called cameraOverlayView. You can set it to a custom view with the button at the bottom that on click switches the pickerController source type to camera.
Read the photo library and present them for selection in a custom view with a button to launch camera which would use the UIImagePickerController with sourceType as camera.
More about overlayView - [UIImagePickerController cameraOverlayView]
Sample code project from Apple - Using UIImagePickerController to Select Pictures and Take Photos
I was using the UIImagePickerViewController, and i wanted to open the camera roll. But, in my app, i have a button to open my camera roll and another one to open my camera. When i take a picture or record a video, obviously i wanted to see those images in my camera roll. But, in my app, when i start to record a video, he doesn't show up in my camera roll's app.
Here's a little bit of code:
UIImagePickerController *cameraRoll = [[UIImagePickerController alloc] init];
[cameraRoll setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[cameraRoll setDelegate:self];
[self presentModalViewController:cameraRoll animated:YES];
At this time i can't see my videos in my camera roll's app. Could someone help me?
You just can do like this:
if([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypePhotoLibrary]) {
UIImagePickerController *picker= [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeMovie, (NSString *)kUTTypeImage, nil];
[self presentModalViewController:picker animated:YES];
}
Sets the file types you want to get on the property of the PickerViewControllerObject "mediaTypes" and you're ready.
You can found the docs types here.
Regards,
Luis