简体   繁体   中英

Hide an UITabBar when Orientation change

I have a quite simple question but the answer is not so easy.

I want to hide a UITabBar when my orientation change.

I looked 2 ways :

Frame way

myAppDelegate.tabBarController.tabBar.frame = CGRectMake(<<bottomOfScreen>>);

Works fine but I have a blank area, so tried to play with tabBarController.view.frame et myViewController.view.frame but I didn't get any good result.

Navigation Controller Way

myOtherVC.hideTabBarWhenPushed = YES;
[self.navigationController pushViewController:myOtherVC animated:NO];

Works but isn't a good solution for my app

Update:

[appDelegate.tabBarController.view removeFromSuperview];
[self.view removeFromSuperview]; [appDelegate.window addSubview:self.view];
self.view.frame = CGRectMake(0,0,480,320);

Works fine but doesn't autorotate anymore (and of course, I didn't change the shouldAutorotate and it always returns YES)


How can I hidde my tabBar and make the current view taking its space ?


Thanks

You can use the current solution combined with:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];

to detect rotation. (I think that you combine this with view.transform = CGAffineTransformMakeRotation to make it rotate...?)

Two ways I think you can easily do this would be:

  1. to reload the objects back into the tabBar controller - with the hidesBottomBarWhenPushed set to YES for the viewControllers you want to be hidden.
  2. The other option would be to just make your view the only view for the window when the phone is rotated and then put the tabBarController.view back in the window when the phone is rotated back

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM