cameraOverlayView of UIImagePickerController disappears immediately - ios

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.

Related

UIImagePickerViewController camera reload tab bar controller (viewDidLoad called)

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;

how to present an UIImagePicker inside the camera

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];
}];

After presenting a modalviewController inside a navigationController, push and pop animations become corrupted

I have a normal NavigationController.
When i open one modalView (using segues) and dismiss it, all the next push and pop animations from the NavigationController gets messy.
Basically it only animates the navigation bar, but the content of that view is not animated(to the left or to the right)!
details:
NavigationController A pushes a viewController B.
ViewController B shoes a modalView.
ModelView is dismissed.
User press back button in viewController B --> The animation to the left (to ViewController A) is not shown!
Does anyone knows what is going on?
Some code (2.show modal):
- (void)sendFilesDidPick:(SendFilesType)type{
switch (type) {
case Library:
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]){
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
picker.allowsEditing = YES;
[self presentModalViewController:picker animated:YES];
}else {
////TODO: Tell user not available
}
break;
default:
break;
}
}
Some code (3.):
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
[self dismissModalViewControllerAnimated:YES];
}
Ok i have a clue: After the modal view appears and dismiss, all the other views that might disappear do not call "ViewWillDissapear". And this is probably what is killing the all thing..
OK i Found the problem!
I had a tabbar subclassed.
In my subclass i was doing this:
- (void)viewDidAppear:(BOOL)animated {
//Custom code
}
I changed to this:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
//Custom code
}
And now every things seems to work properly!!

How do I open a UIImagePickerController from a presented view controller?

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.

How do I implement a UIImagePickerController with a TabBarController

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

Resources