How can I add custom button in UIImagePickerController popover - objective-c

How can I add custom button in UIImagePickerController popover when I am selecting image from gallery?

Got it. These are by default buttons provided by Apple for UIImagePickerViewController. So there is one property you have to use and property is allowsEditing. You have to set it as YES
So that after selecting photo from gallery or camera, those 2 buttons will be shown.
Code should be like:
-(void)openGallery {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
-(void)openCamera {
BOOL isCameraPresent = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
if(isCameraPresent) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
// Add overlay view with custom button on it. Set frames to button as per your choice.
UIView *viewOverlay = [[UIView alloc]initWithFrame:self.view.bounds];
Create and initialise your `UIButton` here
[viewOverlay addSubview:YOUR_BUTTON_OBJECT];
picker.cameraOverlayView = viewOverlay;
[self presentViewController:picker animated:YES completion:NULL];
}
else {
NSLog(#"Camera not present");
}
}
YOU CAN ADD OVERLAY ONLY IF sourceType is UIImagePickerControllerSourceTypeCamera
Make sure that you have confirmed UIImagePickerControllerDelegate protocol in your view controller.
Call those actions on tap of button or action sheet actions as per your choice.
NOTE: UI of popover of UIImagePickerController is dependent on iOS version of device.

Related

When rotate phone to landscape, the UIImagePickerControllerSourceTypePhotoLibrary is turn to camera on sideway

I am new to xcode . In my view controller have images gallery option . User can tab the image to view and add the images. When the user click the add new image option , its show popup there two option like image and camera.
user can add the images from gallery as well as capture the new images from camera. In the case , my camera view working fine. Then i click the gallery view the gallery photos are shown perfectly. But when i rotate the gallery photos view to the landscape ,its automatically goes to the camera in sideway. This is my problem.. I want to when phone rotate the photos gallery in landscape its not going to camera view sideway. Please any one help me.
my code is below
- (void)viewWillAppear:(BOOL)animated {//
[super viewWillAppear:animated];
if (!self.disableGalleryUpdate) {
//This will replace share button in FSImageViewController share button in navigation bar
HPLBarButton *barButton = [HPLBarButton barButtonWithImage:AddNewContractor forTarget:self withSelector:#selector(addObject:)];
self.navigationItem.leftBarButtonItem = barButton;
} else {
self.navigationItem.leftBarButtonItem = nil;
}
APP_DELEGATE.screenHasMultipleOrientation = YES;
[self.navigationController setNavigationBarHidden:NO];
}
- (void)addImageClicked:(id)sender {
[[HPLImageSourceSelectionDeviceManager device] showImageSourceSelectionInView:self.view
withGalleryButtonAction:^{[self camera];}
cameraButtonActionBlock:^{[self gallery];}
];}
-(void)camera
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:nil];
}
-(void)gallery
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:nil];
}
When i choose image gallery view in potrait
and landscpe
e

Shift to UIPopoverPresentationController

I want to create the same popover for my iPhone app with size GGrect of (320 100.0).
Here is my old code:
View * pk1 = [[View alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:pk1];
pop = [[UIPopoverController alloc] initWithContentViewController:nav];
[pop setDelegate:self];
[pop presentPopoverFromRect:[self btnsavepart].frame inView:[self view] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[nav release];
I using this codes but its doesn't change
nav.preferredContentSize = CGSizeMake(320, 100);
I can not change UIpopovercontriller with UIPopoverPresentationController.
How do I specify GGrect of (320 100.0)?
i thinks i can change only on horizontally but how can i do.
View *viewController = [[[View alloc] init] autorelease];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:viewController] autorelease];
navController.modalPresentationStyle = UIModalPresentationPopover;
navController.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;
navController.popoverPresentationController.sourceRect = btnsavepart.bounds;
navController.popoverPresentationController.sourceView = btnsavepart;
navController.popoverPresentationController.delegate = self;
[self presentViewController:navController animated:YES completion:nil];
i want the UIPopoverPresentationController not FullScreen form in iPhone
i adding this codes but i give the FullScreen view
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
{
return NO;
}
I work with Xamarin but its same thing , to specify size of the popover in which you want to display your UIViewController, in the properties of your UIVIewController you have the PreferredContentSize property. There you specify the size.
I saw it somewhere here but forgot where.

Display full camera in iPad

I am try to display full camera in iPad. but it displays very small camera. I am using below this code.
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.delegate=self;
imagePicker.cameraOverlayView.frame = CGRectMake(0, 0, 1000, 700);
[imagePicker.cameraOverlayView sizeToFit];
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
imagePicker.wantsFullScreenLayout = YES;
[imagePicker release];
[popover presentPopoverFromRect:CGRectMake(0,0,400,800)
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
UIImagePickerController is a UINavigationController. Just show it as a full screen modal view controller instead of in a popover.
UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
ipc.delegate = self;
ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
ipc.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:ipc animated:YES completion:nil];
You only need to use a popover on the iPad for selecting images from the photo library. But the camera is allowed to be shown full screen without a popover.

Black Bar in UIImagePicker on iPad - Only in Landscape Right Orientation

I am showing a UIImagePicker (itself in a UIView) via a UIPopOver. This works fine, however when the iPad is rotated onto its right side I get a strange black bar along the left hand side of the popover as per the image below. The cancel button is also partially off the right hand of the screen. This doesn't happen in any other orientation which is odd.
The code is also listed below. Can anyone suggest why I am getting this black bar ?
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
CGFloat width = CGRectGetWidth(self.view.bounds);
CGFloat height = CGRectGetHeight(self.view.bounds);
UIViewController *containerController = [[UIViewController alloc] init];
containerController.contentSizeForViewInPopover = CGSizeMake(width, height);
[imagePickerController.view setFrame:containerController.view.frame];
[containerController.view addSubview:imagePickerController.view];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
Class cls = NSClassFromString(#"UIPopoverController");
if (cls != nil) {
popoverController = [[UIPopoverController alloc] initWithContentViewController:containerController];
[popoverController presentPopoverFromRect:selectedRect inView:self.view permittedArrowDirections:4 animated:YES];
[containerController release];
}
For some strange reason, the view's frame does change in landscape right.
To come over this, set the frame after you present the popover (view code below).
That should do the trick.
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
CGFloat width = CGRectGetWidth(self.view.bounds);
CGFloat height = CGRectGetHeight(self.view.bounds);
UIViewController *containerController = [[UIViewController alloc] init];
containerController.contentSizeForViewInPopover = CGSizeMake(width, height);
[containerController.view addSubview:imagePickerController.view];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
Class cls = NSClassFromString(#"UIPopoverController");
if (cls != nil) {
popoverController = [[UIPopoverController alloc] initWithContentViewController:containerController];
[popoverController presentPopoverFromRect:selectedRect inView:self.view permittedArrowDirections:4 animated:YES];
[imagePickerController.view setFrame:containerController.view.frame];
[containerController release];
}
Also, in your controller, add this to reset the frames when the rotation occurs:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[imagePickerController.view setFrame:imagePickerController.view.superview.frame];
}
The above approach works with iOS 5 and above but on iOS 4 and prior it's not possible to add the UIImagePickerController as a subview and then show it. It always has to be presented as a ModalViewController.
Try this. Reposting one solution I found using [currentDevice endGeneratingDeviceOrientationNotifications]
UIImagePickerController *picker = [[[UIImagePickerController alloc] init] autorelease];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
// Display the camera.
[self presentModalViewController:picker animated:YES];
// Given by default your orientation is in landscape right already
while ([currentDevice isGeneratingDeviceOrientationNotifications])
[currentDevice endGeneratingDeviceOrientationNotifications];
Source: Disable rotation in UIImagePicker

ModalViewController loading on top of another Modal

There may be a better way to do this, and please direct me if there is.
I'm creating an UIImagePickerController with an overlayView in viewDidAppear for 'choose from library', 'take photo', 'flash' 'camera source', etc.
// Set up the camera
imagePicker = [[UIImagePickerController alloc]
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.delegate = self;
imagePicker.cameraOverlayView = [self cameraOverlayView];
cameraOverlayView.backgroundColor = [UIColor clearColor];
imagePicker.showsCameraControls = NO;
imagePicker.toolbarHidden = YES;
imagePicker.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:imagePicker animated:YES];
I then have an IBAction that calls my 'choose from library function', loading another UIImagePickerController to choose a photo from the device.
- (IBAction)library:(id)sender
{
UIImagePickerController *libraryPicker = [[[UIImagePickerController alloc] init] autorelease];
libraryPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
libraryPicker.delegate = self;
[self.imagePicker presentModalViewController:libraryPicker animated:YES];
}
I'm getting a white bar across the top about the size of a status bar when the 'choose from library' modal is presented. I know it has something to do with overlaying a modal on top of a modal, but I don't know how to solve it. (IE, my view layout for 'take photo' navigates fine, although doesn't display the additional 'choose from library' modal).
Any ideas? Any help or direction would be greatly appreciated!
Try
[self presentModalViewController:libraryPicker animated:YES];
Instead of
[self.imagePicker presentModalViewController:libraryPicker animated:YES];