3

enter image description hereI am making a tabBar and navigationBar based application. In it I have a button on a view when I click on it then with the help of UIImagePickerControllerSourceTypePhotoLibrary I have open the image library but the imagePicker default back button, cancel button not shown on view. just like when I use UIImagePickerControllerSourceTypeCamera then camera window is open but I am not able to see the click button to capture the image because it'll hide by tabBar. So please help me out with this problem. Here is the screenshot of image.

Saurabh
  • 423
  • 4
  • 11
  • 22
  • https://stackoverflow.com/questions/29614978/how-to-present-uiimagepickercontroller-from-tab-bar-item –  Sep 26 '18 at 11:38

5 Answers5

7

You can present the image picker on your TabbarController (getting it from your AppDelegate or where you have implemented it) instead of the view controller something like this :

  YourAppDelegate* appDel = (YourAppDelegate*)[[UIApplication sharedApplication] delegate];

[appDel.tabBarController presentModalViewController:picker animated:YES];

Note: From ios 6 presentModalViewController:animated: is deprecated and replaced with presentViewController:animated:completion:

Animesh
  • 1,020
  • 9
  • 8
  • I have not implement tabBar controller through coding, I have used it from storyBoard. So when I right appDelegate_object.taBarController then tabBarController is not there. And I am using tabBar from my Home class so I have try it through Home_object.TabBarController then it compile but application crash. – Saurabh Oct 15 '12 at 06:09
  • I am not so sure about storyBoard but you can check http://stackoverflow.com/questions/8336997/storyboard-uitabbarcontroller for having an idea to get your TabBarController in code. But I am sure that presenting picker from tabbar will solve your problem. – Animesh Oct 15 '12 at 06:19
  • I have added the screenshot of image, in it I want to hide my own navBar and tabBar, and want to show default imagePicker navBar and TabBar. – Saurabh Oct 15 '12 at 07:18
  • Have you tried to get it present through tabbar? Another option will be to present picker from NavigationController like '[self.navigationController presentModalViewController:picker animated:YES]; ' and check what the result is? – Animesh Oct 15 '12 at 07:26
  • Have you got TabBarController in your code and tried presenting picker from TabBar? – Animesh Oct 15 '12 at 08:10
2

In case the project is in storyboards, you won't have a reference to it (That you created in code).

Instead just climb back up the view hierarchy and grab the tab view controller that way.

UITabBarController * tabBarController = (UITabBarController*)self.parentViewController;
[tabBarController presentViewController:picker animated:YES completion:^(void){

}];

You will however have to deal with the camera coming back up after dismissal if you do it in view did appear. (Make some state to prevent that or don't do it there.)

I know its an old question but I figure it will help people for a good time to come as this has worked for me.

Ohmnastrum
  • 113
  • 8
1

For me this line solved the issue and the pickercontroller came above the Tab bar

picker.modalPresentationStyle = .custom;

-1
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.delegate = self; 
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
        picker.wantsFullScreenLayout = YES;

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{

        showImageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
        }
Bajaj
  • 859
  • 7
  • 17
  • I have added the screenshot of image, in it I want to hide my own navBar and tabBar, and want to show default imagePicker navBar and TabBar. – Saurabh Oct 15 '12 at 07:17
  • Please describe, I am not getting you. – Saurabh Oct 15 '12 at 07:24
  • @user1652551 declare tab bar in appdelegate ?? then pickerview declare through present modal view and in picker view hide bottomTabbar them image show in full screen – Bajaj Oct 15 '12 at 07:28
-2
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self; 
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.wantsFullScreenLayout = YES;

    picker.showsCameraControls = YES;
     picker.navigationBarHidden = NO; 
     picker.toolbarHidden = NO;
    picker.allowsEditing=NO;

    [self presentModalViewController:picker animated:YES]; 
ganesh manoj
  • 977
  • 10
  • 24