How to Make UIImagePicker full screen with popover controller for ipad - ios

I have seen other posts on this subject, but no valid solutions. Surely this is possible! I found one solution here that suggests presenting it from a container view controller. The code for that is commented out in my method below. This DOES create the fullscreen view, but the cancel/take photo buttons won't work then, and I can't seem to dismiss it properly. Is there really no simple elegant solution to this???? Please help! Here's my code:
-(IBAction)launchCamera:(id)sender
{
[self.popoverController dismissPopoverAnimated:YES];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
//fullScreenViewController = [[UIViewController alloc] init];
//fullScreenViewController.contentSizeForViewInPopover = CGSizeMake(768, 1024);
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
// Tried making the view full screen (or at least larger), but doesn't work...
//popoverController.contentViewController.contentSizeForViewInPopover = CGSizeMake(384, 512);
[imagePicker setTitle:#"camera"];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];
imagePicker.delegate = self;
imagePicker.allowsEditing = NO;
//[fullScreenViewController.view addSubview:imagePicker.view];
// change imagePicker to fullScreenViewController here for full screen:
popoverController = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[popoverController setDelegate:self];
[popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}

I never could make the UIImagePicker work properly in full-screen, so I ended up using the AVFoundation framework to implement my own.

Related

iOS 9 UIImagePickerControllerSourceTypePhotoLibrary crash when orientation allow only Landscape

I had create app which only support Landscape orientation, whenever I called UIImagePickerControllerSourceTypeCamera to take picture using camera is worked, but when I called UIImagePickerControllerSourceTypePhotoLibrary it crashed.
I had tried using method shouldAutoRotate() to allow portrait but still not working. Any solution for this problem ?
As you are getting this error on iPad
Try the below code and use UIModalPresentationStyle for this purpose :-
self.imagepicker.modalPresentationStyle = UIModalPresentationStyle.Popover
let popover = self.imagepicker.popoverPresentationController
self.imagepicker.preferredContentSize = CGSizeMake(400 ,400)
popover!.sourceView = self.view
popover!.sourceRect = CGRectMake(CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds),0,0)
popover!.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0)
self.presentViewController(self.imagepicker, animated: true, completion: nil)
This is in Swift, I hope you can covert to objective-c easily.
I hope this helps.
Set modalPresentationStyle of your imagePickerController to UIModalPresentationCurrentContext and then present it. Something like,
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
Put Presentviewcontroller code in NSOperationQueue
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
self.presentViewController(self.imagepicker, animated: true, completion: nil)
}];
I give you the solution
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.wantsFullScreenLayout = YES;
UIPopoverController *imagePopover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[imagePopover setDelegate:self];
[imagePopover setPopoverContentSize:CGSizeMake(320, 500) animated:NO]; //set your content size
[imagePopover presentPopoverFromRect:button.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES]; //I give presentPopoverFromRect as button frame.Change here what you want
}

how to open an image picker on ipad just in code

How can I create the image picker in code?
I use iOS 6.0 , with ARC, for ipad.
I would like to able to select the picture and somehow get UIImage of the selected image.
i did add delegates:
enter code here
in the viewDidLoad method did
enter code hereimagePicker = [[UIImagePickerController alloc] init];
and in the button method for click i have put
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:imagePicker animated:YES];
the crash happens in
[self presentModalViewController:imagePicker animated:YES];
There are some tutorials here http://www.raywenderlich.com/130/how-to-write-a-custom-image-picker-like-uiimagepicker and http://mobileorchard.com/ios-advanced-programming-the-image-picker/ that might help you
I have similar code in one of my projects, but I had
[self presentViewController:imagePicker animated:YES completion:nil];
instead of
[self presentModalViewController:imagePicker animated:YES];
Try that and see if it works. Note the presentViewController rather than presentModalViewController.
Add a property in .h
#property (strong) UIPopoverController *pop;
In you r .m file under your button implimentation add something like:
if (self.pop) {
[self.pop dismissPopoverAnimated:YES];
}
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePickerController.delegate = self;
imagePickerController.allowsEditing = YES; //if you want to edit the image
self.pop=[[UIPopoverController alloc] initWithContentViewController:imagePickerController];
//choose the direction of the arrow for the popover
[self.pop presentPopoverFromRect:((UIButton *)sender).bounds inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
Make sure you have your <UIPopoverControllerDelegate> delegate set in .h

shouldAutorotateToInterfaceOrientation in ios6

I am using UIImagePickerviewController to open the photo library through the below attached code... after called bit lines of code. The application was crashed... Its working fine in ios5
UIImagePickerController* content = [[UIImagePickerController alloc] init];
content.delegate = self;
content.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:content animated:YES];
[content release];
Is anything wrong with this code?
Check Crash on presenting UIImagePickerController under ios6 You will get everything you need to make UIImagePickerviewController working on iOS 6.0.
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[popover presentPopoverFromRect:cameraButton.frame inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
else{
[self presentModalViewController:imagePicker animated:YES];
}
I had the same issue. Because the UIImagePicker shows on portrait mode.
I fixed it by subclassing the UIImagePicker and implementing the shouldAutorotate method like:
- (BOOL)shouldAutorotate
{
return NO;
}
I have created instance of my subclassed imagePicker instead of UIImagePicker, everything worked fine. Hope this will help you.

Test ipad 2 camera with xcode simulator IOS 5

I am testing ipad camera application with ipad simulator
I used below code, change the source type instead of camera.
-(IBAction)useCamera:(id)sender{
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]){
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate =(id<UINavigationControllerDelegate,UIImagePickerControllerDelegate>) self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage,nil];
imagePicker.allowsEditing = NO;
[self presentModalViewController:imagePicker animated:YES];
[imagePicker release];
newMedia = YES;
}
}
When it run in the simulator error came up in ios 5 simulator .
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:'On iPad, UIImagePickerController must be presented via UIPopoverController'
But its working on 4.3 simulator
Starting with iOS5 you need to show the pickercontroller in a popover view rather than a modal view.
From the apple documentation: On iPad, present the user interface using a popover. Doing so is valid only if the sourceType property of the image picker controller is set to UIImagePickerControllerSourceTypeCamera. To use a popover controller, use the methods described in “Presenting and Dismissing the Popover” in UIPopoverController Class Reference.
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html
Here is an example of presenting a UIImagePickerController inside a popover view:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[popover presentPopoverFromRect:CGRectMake(0.0, 0.0, 400.0, 400.0)
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];

How to access photo library for ipad apps

I am facing a problem when I try to access the photo library when developing iPad apps. However, the same code works properly for iPhone dev. The error which is generated is:
On iPad, UIImagePickerController must be presented via UIPopoverController
I am using the following code for iPad development:
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
[picker release];
}
Try presenting with a pop over controller in iPad, doesn't support modal view controller
even I encountered the same problem, so tried using pop over controller and it works now :)
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
popControl = [[UIPopoverController alloc]initWithContentViewController:picker];
popControl.delegate=self;
[popControl presentPopoverFromRect:browseButton.bounds inView:mainView permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];

Resources