Present a view controller in the background - objective-c

I am having a problem with presenting a view controller while another one is already presented.
In my app, I present a UIImagePickerController, which after selecting an image (either from the library or through the device's camera) should return to another view controller.
For example, let's say you clicked a camera button which launches the camera, and after you take a picture, the camera slides down, but the view you see is not the one with the camera button but a view which lets you edit the metadata of the image.
Does anyone know a way to accomplish this task?
Thanks ahead, iLyrical.

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
[picker dismissModalViewControllerAnimated:NO];
NewViewController *viewController = [[NewViewController alloc] init];
viewController.image = image;
[self presentModalViewController:viewController animated:NO];
}
And if you can use iOS 5.0 or newer:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
[picker dismissViewControllerAnimated:YES completion:^(){
NewViewController *viewController = [[NewViewController alloc] init];
viewController.image = image;
[self presentViewController:viewController animated:NO completion:nil];
}];
}
Check Apple's doc on UIViewController Class Reference

If you are able to initialize the final viewController before presenting UIImagePickerController, you can try:
Initialize final viewController
Set it hidden or its view's alpha=0 and push non-animated
Present imagePicker viewController
Set the final viewController non-hidden
Dismiss modal viewController

Related

nav bar nonresponsive after UIImagePickerController dismissed

On iOS 7 only, the navigation bar in my app does not respond to any touches after a UIImagePickerController is used and then dismissed (whether a pic has been selected or not). The screen below the navigation bar functions as normal, but it is now impossible to navigate Back in the app; the user is stuck on this screen.
I am launching the UIImagePickerController from code, though the rest of the app is laid out in storyboards.
UIImagePickerController *mediaUI = [[UIImagePickerController alloc] init];
mediaUI.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
mediaUI.mediaTypes = [NSArray arrayWithObject:(NSString *) kUTTypeImage];
mediaUI.allowsEditing = NO;
mediaUI.delegate = self;
[controller presentModalViewController: mediaUI animated: YES];
Thanks in advance for any help.
I hope you are performing these steps correctly!
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
And when you are calling
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
Cheers!
I noticed that the log was showing "Unbalanced calls to begin/end appearance transitions for" the launching controller. I was launching the image picker controller immediately from another controller when it appeared. This works OK on iOS 8 but there needs to be a delay on iOS 7. I fixed it by calling my method after a brief delay:
[self performSelector:#selector(takePicture) withObject:nil afterDelay:.1];

IOS Image disappear on selecting another event

Hi i am getting image from gallery by UIImagePickerController and shows on my view controller, i have textfield also when i enter text in textfield my image disappear. Please help me what is issue with this. my UIImagePickerController delegate method is
-(IBAction)btnBackAction:(id)sender{
[self.navigationController popViewControllerAnimated:YES];
}
-(IBAction)imageactoin:(id)sender{
UIImagePickerController *pickerController = [[UIImagePickerController alloc]
init];
pickerController.delegate = self;
[self presentModalViewController:pickerController animated:YES];
}
#pragma mark UIImagePickerControllerDelegate
- (void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
self.imageView.image=image;
[self dismissModalViewControllerAnimated:YES];
}
#end
please help me whats issue that my image not disappear by selecting another event like textfield.
The below delegate method is deprecated from iOS 3.0
- (void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo
You have to use this one,
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}

Image Picker on ipad

I know image picker on the iPad needs to be a popover, and I keep trying but it won't work and crashes when I tap the button that calls the popover.
-(IBAction)addPhoto:(id)sender{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
popover=[[UIPopoverController alloc]
initWithContentViewController:imagePicker];
[popover presentPopoverFromRect:((UIButton *)sender).frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)selectedImage editingInfo:(NSDictionary *)editingInfo {
// Delete any existing image.
NSManagedObject *oldImage = imageClass.image;
if (oldImage != nil) {
[imageClass.managedObjectContext deleteObject:oldImage];
}
// Create an image object for the new image.
NSManagedObject *myImage = [NSEntityDescription insertNewObjectForEntityForName:#"Image" inManagedObjectContext:imageClass.managedObjectContext];
imageClass.image = myImage;
// Set the image for the image managed object.
[image setValue:selectedImage forKey:#"image"];
[self dismissViewControllerAnimated:YES completion:nil];
}
Based on the exception you are getting, the problem is that the sender for the addPhoto method is actually a UIBarButtonItem, not a UIButton. You need to change how the popover is displayed from using the button's frame to being displayed from the bar button.
-(IBAction)addPhoto:(UIBarButtonItem *)sender {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
popover = [[UIPopoverController alloc]
initWithContentViewController:imagePicker];
[popover presentPopoverFromBarButtonItem:sender
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
Try to create property to store Your popover controller or store content controller. Seems that one of view controllers releases right after end of method. Also, iOS 7 have awful behavior of UIImagePickerController in popover.
This is related question.

Switch Views After UIImagePickerController

I'm trying to make my app switch to another view when the user finish selecting an image, but what happen is when the user finish picking the image, it dismisses the picker and comes back to the same view.
Here's my code:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
[picker dismissModalViewControllerAnimated:YES];
DrawingViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:#"Drawing"];
viewController.image.image = image;
[self presentModalViewController:viewController animated:NO];
}
That happens because you're dismissing the picker modal view controller with animation and presenting the new view controller right away. You can only present a new modal view controller after the previous one has been dismissed.
A solution would be to dismiss the picker modal without animation :
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
[picker dismissModalViewControllerAnimated:NO];
DrawingViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:#"Drawing"];
viewController.image.image = image;
[self presentModalViewController:viewController animated:NO];
}
Another solution (that works only on iOS 5) is to use the dismissViewControllerAnimated: completion: method :
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
[picker dismissViewControllerAnimated:YES completion:^(){
DrawingViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:#"Drawing"];
viewController.image.image = image;
[self presentModalViewController:viewController animated:NO];
}];
}

UIImagePickerController custom overlay preview taken photo

I'm creating custom camera controls using the UIImagePickerController. The problem I'm having is this:
When the user takes a photo, I would like to show a preview of the photo they have just taken. I have managed to do this by displaying a UIImageView over the camera viewfinder. The only problem is that there is a visible delay before the imageview is shown. Any ideas? My code is shown below
- (void)viewDidLoad
{
[super viewDidLoad];
picker = [[UIImagePickerController alloc] init];
[picker setSourceType:UIImagePickerControllerSourceTypeCamera];
overlayViewController = [[CameraOverlayViewController alloc] initWithNibName:nil bundle:nil];
[picker setCameraOverlayView:overlayViewController.view];
[picker setShowsCameraControls:NO];
[picker setDelegate:self];
[self.view addSubview:picker.view];
}
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *img = [info objectForKey:UIImagePickerControllerOriginalImage];
[overlayViewController.imgView setImage:img];
[overlayViewController.imgView setHidden:NO];
return;
}
The UIImagePickerController is a subclass of UINavigationController. You can create a custom preview view controller (just a view controller containing an image view and the cancel and use buttons) and push it on the image picker controller.