views:

616

answers:

4

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

A: 

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;
        }
    }
}
bisand
Hi thiere... i have not tried this....but i would not know where to put it?
Tom G
You should put it in the ViewController of the view you want the rotation notification to occur.
bisand
A: 

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

pkaur
A: 

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!

Tom G
A: 

@ Tom G

hi dude

i followed ur steps

but these r the 2 warnnings m getting,and bcoz of that,application gets crahed.

warning #1 : 'TaplistenerSubImageView' may not respond to ' warning #2 : return makes integer from pointer without a cast

plz let me knw what should do next.

regards shishir

shishir.bobby