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 accomp开发者_如何学Pythonlished this task any advice would be greatly appreciated!
Thanks
Tom
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!
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;
}
}
}
can you actually hide the tabbar in the UItabbarController? Atleast the nib doesn't allow you to select none from the bottom bar dropdown.
精彩评论