2
votes

Has anyone successfully hidden a UITabbar when rotating the device?

I have one view in the UItabbar controller that i rotate (So effectively one tab that rotates)

When this happens i want the tab bar to disappear... but nothing seems to work!

Either the tabbar still remains visible

Or it disappears along with the view

Or the tabbar disappears and the view no longer rotates!

So if anyone has successfully accomplished this task any advice would be greatly appreciated!

Thanks

Tom

3
Have you tried showing a modalViewController when the device is rotated so that it is not part of the TabBarController?willcodejavaforfood
This would not work for me because i am displaying a webview... so if i were to do this it would mean reloading the webview on rotationTom G

3 Answers

2
votes

Sorry for the late reply pk

I managed to rotate and hide the tab bar.

First it was a case of subclassing the UITabBarController, and including this method:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    //This allows us to get the rotation calls from any view in the tab bar
    // 

    return [self.selectedViewController shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation];
}

And then you can rotate from only the required view controllers.

To hide the tab bar:

Get reference to the app delegate and the Tab bar controller, and then set the tab bar to hidden:

MyAppDelegate *delegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
UIView *tabBar = [delegate.tabBarController.view.subviews objectAtIndex:1];
tabBar.hidden = TRUE;

Hope this helps!

1
votes

Have you tried to add an observer on the UIDeviceOrientationDidChangeNotification notification in view controller, and do the "Hidden = true or false" on this callback?

I successfully accomplished this with the following C# code using the MonoTouch framework.

void Initialize ()
{
    NSNotificationCenter.DefaultCenter.AddObserver("UIDeviceOrientationDidChangeNotification", DeviceRotated);          
}

private void DeviceRotated(NSNotification notification)
{
    if ( notification.Name.Equals("UIDeviceOrientationDidChangeNotification") )
    {
        Console.WriteLine(UIDevice.CurrentDevice.Orientation.ToString());
        if ( UIDevice.CurrentDevice.Orientation != UIDeviceOrientation.Portrait ) 
        {
            tabBar.Hidden = true;
            //Plus some additional logic.
        }
        else
        {
            tabBar.Hidden = false;
        }
    }
}
-1
votes

can you actually hide the tabbar in the UItabbarController? Atleast the nib doesn't allow you to select none from the bottom bar dropdown.