I have looking for a complete tutorial on google and stack of a complete example on using the UIImagePicker to get a picture from the camera and a picture from the library or camera roll on the iPad 2.
I have found code snippets saying just add the PopOverController in, but have not been able to implement it successfully.
thanks in advance.
This worked for me.
I do it like this I detect if iPhone or iPad and in the popover where it says (self.album.bounds) is just were you want the popover arrow to appear in this case self.album is the button that fires the below action
-(IBAction)selectPicture:(id)sender {
NSLog(#"Image is not set");
// Create image picker controller
thePicker = [[UIImagePickerController alloc] init];
// Set source to the camer roll;
thePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
// Delegate to self
thePicker.delegate = self;
//Allow editing of image NO
thePicker.allowsEditing = NO;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
[self presentModalViewController:thePicker animated:YES];
}
else{
popover = [[UIPopoverController alloc]initWithContentViewController:thePicker];
[popover presentPopoverFromRect:self.album.bounds inView:self.album permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
popover = popover;
}
}
Related
I am opening photo library from a button in UIPopover, but photo library is displayed behind the popover.
I am presenting popover as follow.
[self.commentsPopover presentPopoverFromRect:rectInSuperview inView:self.superview permittedArrowDirections:UIPopoverArrowDirectionLeft | UIPopoverArrowDirectionRight animated:YES];
self.commentsPopover is UIPopoverController.
After popover is displayed, I am opening photo library against button in popover.
self.attachmentPicker = [[ELCImagePickerController alloc] initImagePicker];
self.attachmentPicker.maximumImagesCount = MAX_ATTACHMENT_COUNT;
self.attachmentPicker.returnsOriginalImage = NO; //Only return the fullScreenImage, not the fullResolutionImage
self.attachmentPicker.imagePickerDelegate = self;
self.attachmentsView.delegate = self;
self.attachmentPicker.modalInPopover=YES;
self.attachmentPicker.modalPresentationStyle = UIModalPresentationFormSheet;
[MKGlobals presentViewController:self.attachmentPicker animated:YES completion:^{
self.attachmentPicker = nil;
}];
This displays photo library behind the popover.
Follow image describes scenario.
This code is working fine in iOS < 8.x.
Any help will be appreciated.
My app is structured with a central view controller that adds 3 to 4 subviews to the main view. In one of the added view controllers I present a camera to the user. When I dismiss the image picker, every subview except the one in which I present the camera (the view controller) disappears. I think it might be related to how the app is structured and the view stack. The app works fine when running iOS 8 on an iPhone and iOS 7 on an iPad. I am having this issue only when I am running iOS 8 on the iPad. I made sure the code followed the apple documentation on how to present and dismiss the image picker. Here is the code used to present the image picker.
-(IBAction)photoButtonPressed:(id)sender
{
// Prompt for camera or photo library
// Retrieve image and set it as this button's default image
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage, nil];
imagePicker.allowsEditing = NO;
imagePicker.modalPresentationStyle = UIModalPresentationFullScreen; //play around with this
[self presentViewController:imagePicker animated:YES completion:nil];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Camera not found" message:#"There is no camera available on this device." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
}
Code used to dismiss
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
CGSize scaleSize = CGSizeMake(1024.0f, 1280.0f);
UIImage *capturedImage;
// Handle a still image capture
capturedImage = (UIImage *) [info objectForKey:
UIImagePickerControllerOriginalImage];
[self dismissViewControllerAnimated:YES completion:nil];
if (capturedImage) {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
photoData = UIImageJPEGRepresentation([capturedImage resizedImage:scaleSize interpolationQuality:kCGInterpolationHigh], 5);
photoEntity = nil;
[self.takePhotoButton setImage:[UIImage imageWithData:photoData ] forState:UIControlStateNormal];
if ([self isAnyButtonSelected] || ![_answerTextField.text isEqualToString:#""] || !_questionBoolean.hidden) {
[Tools enableControl:_saveButton];
}
} else {
newPhotoData = UIImageJPEGRepresentation([capturedImage resizedImage:scaleSize interpolationQuality:kCGInterpolationHigh], 5);
photoEntity = nil;
}
}
}
And here I tried messing with the parent views and controllers in this method. I was able to get the app to return to the central view controller minus the current view controller that is in charge of taking the photos. The only problem is that the app's touch is now disabled and I am missing one view.
- (void) imagePickerControllerDidCancel: (UIImagePickerController *) picker
{
// [self willMoveToParentViewController:nil];
// [picker.view removeFromSuperview];
// [picker removeFromParentViewController];
[self dismissViewControllerAnimated:YES completion:nil];
}
I was going to post photos but I am currently unable to because I am new to stack overflow. Any help would be appreciated. Thanks!
Ok so the app is not using story boards but it is using xib files. It is inherited code and the app was created several years ago. There are multiple view controllers with multiple views. There is a central view controller where all the other view controllers are added to the central view.
[self.view addSubview:_catViewController.tableView];
[self.view addSubview:_listViewController.tableView];
[self.view addSubview:_queryViewController.view];
[self.view bringSubviewToFront:_queryViewController.view];
queryViewController is where I am taking the photo. When I dismiss every view is gone except the query view controller which happens to take up the entire screen (it previously did not). Let me know if I need to add more information! Thanks
So, the general problem is that your central view controller is adding the views of other view controllers to itself. You can't do that -- it breaks view controller encapsulation. And when you violate encapsulation, stuff just breaks. (That's a vague statement, but 100% true :-p) Unfortunately, you either need to stab in the dark to find a hack to make it work, or repartition the problem to respect encapsulation. The latter is probably better if you'll need to maintain this code in the future.
I have tabbar as Root controller. When i choose camera from view controller then it opens in Portrait mode, and then i change its orientation but it still in portrait mode and when pickerview dismissed and again change main view controller to landscape mpde then all 5 tabbar items are shown on left side. So it looks like all tabbar items icons are get disturbed. Can any one help to change camera orientation when phone orientaiton gets changed?
if (self.pickerView) {
self.pickerView = nil;
}
self.pickerView = [[UIImagePickerController alloc] init];
self.pickerView.delegate = self;
self.pickerView.sourceType = UIImagePickerControllerSourceTypeCamera;
self.pickerView.showsCameraControls = YES;
self.pickerView.wantsFullScreenLayout = YES;
self.pickerView.navigationBarHidden = YES;
self.pickerView.toolbarHidden = FALSE;
self.pickerView.allowsEditing=YES;
[self presentViewController:self.pickerView animated:YES completion:NULL];
I am trying to get the IPAD to choose a photo from the photo album
pickerController = [ [ UIImagePickerController alloc ] init ] ;
pickerController.delegate = self ;
pickerController.editing = NO ;
pickerController.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[ self presentViewController : pickerController animated : YES completion : nil ] ;
The app keeps crashing when I use it on iPad, but works fine on iPhone.
This one got me before too. On the iPad if you specify a source type of UIImagePickerControllerSourceTypePhotoLibrary or UIImagePickerControllerSourceTypeSavedPhotoAlbum you need to present the image picker controller using a popover controller. If you try to present it modally, like you are doing, you will get an exception.
Not 100% required, but it's also a good idea to use the test to see what source types are available.
[UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]
The source types are:
UIImagePickerControllerSourceTypePhotoLibrary
UIImagePickerControllerSourceTypeSavedPhotosAlbum
UIImagePickerControllerSourceTypeCamera
This is how I solved this issue to test if it is an iPad or not.
if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
UIPopoverController* popOverController = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
[popOverController presentPopoverFromRect:selectVideoToViewButton.bounds inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}else {
[self presentModalViewController:self.imagePickerController animated:YES];
}
I have been beating my head on this for a few hours. I have some sample code (using a UINavigationController) when the view loads the camera roll will be presented. However, when I try to incorporate the same code into my app, which has a tabBarController, I get a blank modal UIImagePickerController. I didn't track down what I am doing wrong.
// bring up image picker
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {
NSLog(#"UIImagePickerControllerSourceTypePhotoLibrary available");
UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
ipc.delegate = self;
ipc.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
ipc.allowsEditing = YES;
[self.tabBarController presentModalViewController:ipc animated:YES];
[ipc release];
}
Any insight would be appreciated.
Not sure what has changed, but this is possible by calling presentViewController from your tabBarController. This is the standard now and ensures your camera or image picker always gets presented as a full screen modal view.
For reference: presentViewController