开发者

Modally present UIImagePickerController does not hide UITabBar if current view has UINavigationController as container controller

I have a tabbar app and the second tab goes to a navigation controller-style view.

on the rightButton of the navigation bar I have a camera icon to present modally the ImagePicker. However it will not become fullscreen but instead underlay the tabbar.

The first image show that I have a navigation controller container this first rootView which has a camera button. When click it will just create a UIImagePickerController and present it modally. Nothing special.

first http://www.jobline.com.sg/images/no_use/1.png

However the result of the camera is missing the control to take/cancel picture like this:

second http://www.jobline.com.sg/images/no_use/2.png

How do I hide the UITabBar and able to see the camera control? I know it can be done because the Skype profile tab also have a camera and then present a UIActionSheet to "Take picture" and then the full-screen camera view. I believe the profile tab has navigation controller as its root view also.

Thanks a million for your help.

Here is the code that I used:

- (void)takePicture:(id)sender {
  UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

  if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
    imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
  } else {
    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
  }

  [self presentModalViewController:imagePicker animated:YES];
}

It is a fairly st开发者_JAVA百科raightforward code of presenting an imagePicker modally. So I wonder why there is no camera control and how come my tabbar can overlap it. Is it because of my view hierarchy?


Ok, i have a solution, but it is somewhat "hacky." My idea is to post a notification to NSNotificationCenter that calls a method which hides the tabbar. An example:

Inside the application delegate (or whatever controls your tabbar...)

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hideTabbar) name:@"hideTab" object:nil];
    // Override point for customization after application launch.
    // Add the tab bar controller's current view as a subview of the window
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}

-(void)hideTabbar{
    [[_tabBarController tabBar] setHidden:YES];
}

And then to hide the tab bar when the camera view appears just post the notification, like so

[[NSNotificationCenter defaultCenter] postNotificationName:@"hideTab" object:nil];

And then of course have one to unhide it when the camera view goes away.

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜