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
Related
I trying to write some app with objective-c for iOS.
I have a project with tap bar controller.
In my last tap I've button click on this I will show camera.
So when I took my photo with camera, and tap on "Use photo", it's call ViewDidLoad of parent controller of my TapBarViewController, and my tap controller reload with changeative tap
I also tried to google
but there are no solutions..
thisand this doesn't work for me.
Please, what I do wrong?
My method witch call camera is:
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:nil];
UPDT:
Also I think that it is not resource problem like described here
Ok, after one day of researching I found the solution.
after that I added this line it's work fine.
picker.modalPresentationStyle = UIModalPresentationCustom;
My Storyboard contains a CameraViewController in which I designed my custom overlay view.
As long as I use it as one tab of my UITabbarController, the cameraOverlayView is visible. But if I segue to this view controller from any other VC, the overlay view is visible only for a fraction of a second, then only the preview image is visible.
#implementation CameraViewController
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
UIImagePickerController *picker = [UIImagePickerController new];
if (![UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) return;
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls = NO;
picker.allowsEditing = NO;
picker.cameraOverlayView = self.view;
[self presentViewController:picker animated:YES completion:nil];
}
I have tried any segue types, presentation styles, etc., the problem stays the same.
I inserted some logs in viewDidDisappear, and noticed that this function in fact is called, I guess that's the reason why the overlay disappears.
Keep in mind: If I just open the tab of my Tabbarcontroller, everything just works fine! The problem only occurs if I segue to the CameraVC.
Thanks in advance!
The solution is to select modal presentation style and "Over current context", because then the viewDidDisappear event is not triggered.
So what am I trying to do here is just to open the camera roll from within a custom camera overlayView. I implemented the custom camera overlayView, created a UIImagePickerController, and replaced the default overlay with my custom one. Then I created another instance of UIImagePickerController, set the sourceType to PhotoLibrary and tries to present it when a button on the overlayView is pressed.
The below error message shows when i press the button:
Warning: Attempt to present <UIImagePickerController: 0x14da5440> on <UINavigationController: 0x14e63760> whose view is not in the window hierarchy!
Here is my code:
- (IBAction)select:(id)sender
{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.allowsEditing = NO;
[self presentViewController:imagePicker
animated:YES completion:nil];
}
}
Does anyone know what's the problem here?
Thanks!
you need to use completion block for present one view controller when another view controller dismiss like following:
[self dismissViewControllerAnimated:YES completion:^{
[self presentViewController:imagePicker
animated:YES completion:nil];
}];
I am using the UIImagePicker to select a photo from the users photo library.
Here is my setup:
MenuViewController (UINavigationController class) that has a tweet button.
Click the tweet button, it presents modally a custom tweet composer.
Select the "Camera Roll" button and I call UIPickerView which is also presented modally.
When you select camera roll (or any album) I get this error:
2013-08-03 02:25:41.842 appName[2145:f803] nested push animation can result in corrupted navigation bar
and my custom back button now looks like this:
instead of:
Here is the code that displays the tweet composer:
- (IBAction)tweetButtonPressed:(id)sender {
KBTweetComposer *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"new_tweet"];
vc.defaultText = #"";
[self presentViewController:vc animated:YES completion:nil];
}
Here is how I'm presenting the picker view:
- (void)photosButtonPressed:(id)sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:nil];
}
I am using storyboards, but I am not using segues, just as a side note. I have found quite a few different people on StackOverflow who have the same error but a completely different circumstance.
It may be related to Presenting a UIViewController that then presents another UINavigationController (The UIImagePicker by default has a Nav Controller) in addition to the original.
How can I get around this? Any help would be great, thanks!
Update at bottom of question
Here's what I'm looking to do:
Main ViewController opens a new ViewController (i don't want a navigation bar, so do I have to do this modaly?) which then opens the camera.
In the main view controller I have this being called on a button press:
CameraProcessViewController *controller = [[CameraProcessViewController alloc] initWithNibName:#"CameraProcessViewController" bundle:nil];
[self presentModalViewController:controller animated:NO];
Which opens up the next controller. In that next controller in the viewDidLoad method I have:
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePicker setDelegate: self];
[imagePicker setAllowsEditing:NO];
[self presentModalViewController:imagePicker animated:YES];
NSLog(#"Has camera");
} else {
NSLog(#"Has no camera");
}
I've tried both presentModalViewController and presentViewController and every combination of the two between the main view controller and this child one, however the camera never opens. When I move the camera code into the main view controller it opens fine.
I've looked and looked and I can't find anything saying why this would be.
Thanks!
UPDATE
I found that in the viewDidLoad method I can call this:
[self performSelector:#selector(openCamera) withObject:nil afterDelay:0];
And it loads it up just fine. Is this okay or is this not recommended? Seems a tad hacky!
viewDidLoad is not the right place to do this. You could try viewWillAppear but that might be too early, too. Otherwise, viewDidAppear.