Presenting UIImagePickerController over modally presented view controller does not work correctly in iOS 8 - ios8

I have presented UIImagePickerController from modally presented view controller. After clicking the image I get a black image instead of the clicked picture
I did something Like this.
//From ViewController1 I presented view controller2 with
- (IBAction)buttontappedToPresentViewController2:(id)sender
{
ViewController2* controller2 = [[ViewController2 alloc] initWithNibName:#"ViewController2" bundle:nil];
controller2.modalPresentationStyle = UIModalPresentationPageSheet;
[self controller2 animated:YES completion:nil];
}
//In ViewController2, I presented the UIIMagePickerController
- (IBAction)cameraButtonTapped:(id)sender
{
UIImagePickerController *cameraController = [[UIImagePickerController alloc] init];
cameraController.mediaTypes = #[(NSString *)kUTTypeImage,(NSString*)kUTTypeMovie];
cameraController.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:cameraController animated:YES completion:NULL];
}
After clicking the image you will get black screen instead of the captured image with retake and use photo options. If you select "Use Photo" option you get the correct image in callback.
Note: If you do not set UIModalPresentationStyle for viewController2, the code works fine.
Any idea what is going wrong here.
EDIT: I have used XCODE 5.1 and my target deployment is iOS 7. I am running the app on iOS8 device.

Related

make modally presentation from UISplitViewControllers primary view to detail view

I have a plus button in my primary view controller of a UISplitViewController and i want to present something modally in my detail view, just like apple does when adding a new contact in address book in iPad. I have tried everything but nothing. I managed to do it but when i am trying to embed my presented view controller into a UINavigation controller then my presented controller covers the full screen. Any suggestions? Here is my code:
UINavigationController *navController = [self.splitViewController.viewControllers lastObject];
DetailTableViewController *controller = (DetailTableViewController *)navController.topViewController;
controller.definesPresentationContext = YES;
controller.providesPresentationContextTransitionStyle = YES;
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
EditTableViewController *etvc = (EditTableViewController *)[storyboard instantiateViewControllerWithIdentifier:#"EditTableViewController"];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:etvc];
etvc.patient = patient;
if (IDIOM == IPAD)
{
etvc.modalPresentationStyle = UIModalPresentationCurrentContext;
[controller presentViewController:nav animated:YES completion:nil];
} else {
[self presentViewController:nav animated:YES completion:nil];
}
I just successfully solved this problem by creating a custom segue whose implementation is:
- (void)perform
{
UIViewController *ctrl = self.sourceViewController;
UIViewController *dest = self.destinationViewController;
dest.modalPresentationStyle = UIModalPresentationCurrentContext;
[ctrl presentViewController:dest animated:YES completion:nil];
}
I'm seeing the behavior I want by invoking this segue from my detail view controller on the modal view I want to overlay it.
I think where your code is going haywire is here:
etvc.modalPresentationStyle = UIModalPresentationCurrentContext;
I think it should be:
nav.modalPresentationStyle = UIModalPresentationCurrentContext;
Though I haven't tested it.
Note that the Apple docs suggest that modalPresentationStyle is ignored on the iPhone (or on "horizontally compact devices"), so your "IS_IPAD" check may be redundant.
Hope this helps!

iOS 7: Restrict device current orientation when modal view controller is presented

I have a UIViewController which contains a UICollectionView. On tapping any of the UICollectionViewCell I present a modal view controller.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
PopViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"DetailsView"];
vc.view.backgroundColor = [UIColor clearColor];
vc.transitioningDelegate = self;
vc.modalPresentationStyle = UIModalPresentationCustom;
[self presentViewController:vc animated:YES completion:nil];
The PopViewController shows up correctly. Now I want to restrict the device orientation when PopViewController is being presented. That is if PopViewController is presented in portrait mode then it should not change to landscape even if I switch to landscape mode (using Rotate Left or Right in simulator) until I dismiss the PopViewController.
I have used following code in PopViewController:
-(BOOL)shouldAutorotate {
return NO;
}
What else (or instead) is needed to lock the pop up view to the current orientation?
in your modal controller try to add this, also (iOS > 6)
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
to support iOS 5 or below you must additional add:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}

ipad: keybord at wrong position

When I have switched to another view (After returning from taking a picture or after switching to a view to select stuff in table) the ipad keyboard appears at the wrong position.
When I select a text field, I see this on my Ipad and on the simulator. (can't post images yet). If I turn my ipad (so that it aligns horizontal) and rotate back the keyboard is back normal.
https://devforums.apple.com/servlet/JiveServlet/showImage/2-701040-19966/Screen+Shot+2012-07-20+at+16.36.20.png
My code to switch to the camera for taking a picture...
- (IBAction)getCameraPicture:(id)sender
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.title = #"CameraPicture";
[self presentModalViewController:picker animated:YES];
}
My code to switch to a view with a table in it :
[self presentModalViewController:viewControllerSpanoTechProducts animated:YES];
code for returning after selecting stuff :
[self dismissModalViewControllerAnimated:YES];
how my app works: you have a main screen with buttons and textfield to fill in a form. when you push a button to select a product I switch to another viewcontroller with a table where you can select a product and a button 'done'. If you click the 'done' button I switch back to the original view.. hope this helps?
I'm just started with iOS.. Any help is appriciated!
At the time of switch user this code:
[yourTextFieldObject resignFirstResponder];
This might work.

UIImagePickerController within existing UIPopoverController resizing issue on iPad

I am working on an iPad app where I have a button that generates a popover controller that I am populating with a specific view controller. Here is the button code that generates the UIPopoverController and loads it with a specific view (signUpListAddEditViewController):
-(void)addSignUpList:(id)sender {
signUpListAddEditViewController = [[SignUpListAddEditViewController alloc] init];
popover = [[UIPopoverController alloc] initWithContentViewController:signUpListAddEditViewController];
popover.popoverContentSize = signUpListAddEditViewController.view.frame.size;
[popover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
signUpListAddEditViewController.popover = popover;
}
Inside SignUpListAddEditViewController.m, I have several fields and a tableview. One of the fields is a UIButton where I display an image and allow the user to load a new image using this button. Since I am already in a popover, I swap the content controller with the UIImagePickerController. So far, so good.
-(void)takePicture:(id)sender
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[popover setPopoverContentSize:popupScreenSize animated:YES]; // popupScreenSize is a CGSIZE set to 500 x 900
[popover setContentViewController:imagePicker animated:YES];
}
The view is swapped out with the imagePicker with the size remaining the same as the original view and I can see the various picture galleries (Camera Roll, Photo Stream, etc). Here is where it gets strange. As soon as I pick one of the galleries, the view is replaced with a thumbnail view of the pictures in that gallery AND THEN the view resizes to a much narrower width. The images are distorted and nearly impossible to select one of them.
I have tried setting [popover setPopoverContentSize:CGSIZE animated:YES] prior to every access to the popover controller, with everything resizing properly EXCEPT the detailed image view? Any ideas where I can override the thumbnail image gallery view?
Here is the code for the didFinishPickingMediaWithInfo method where I again override the content size:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
[thisList setThumbnailDataFromImage:image];
[popover setPopoverContentSize:popupScreenSize animated:YES];
[popover setContentViewController:self animated:YES];
listImageButton.imageView.image = image;
}

Allowing the user to edit a UIImage

I have let the user select an image using UIImagePickerController.
The resulting image is shown in a UIImageView.
There is a UIButton below the image with the title "Edit Image".
My question is, How or to where to i present modal view controller to allow the user to edit the image?
This code allows the user to edit the image s/he has chosen...
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:imagePicker animated:YES];
... but i want the user to be able to edit this image after s/he has picked it as well.
How would i go about doing this?
Perhaps a screen like this:

Resources