问题
Hide tabbar in IOS7 shows informal behaviour
When I use
self.tabBarController.tabBar.hidden = YES;
Above code hides the tabBar, but my view from bottom does not remain interactive
But when I uses this just before pushing viewController in navigation
someViewController.hidesBottomBarWhenPushed = YES
[self.navigationController pushViewController:someViewController animated:YES];
It hides tabbar as well as view from bottom is also interactive. but problem in this case is, when we pop viewController it shows black bar just above tabbar for few seconds.
回答1:
I hope you got the solution. Just to make sure, did you try
self.edgesForExtendedLayout = UIRectEdgeBottom;
回答2:
Try this, if you want to hide/show the UITabBarController of view:
For hide the tabbar:
- (void)hideTabBar:(UITabBarController *) tabbarcontroller
{
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
}
}
}
for show Tabbar:
- (void)showTabBar:(UITabBarController *) tabbarcontroller
{
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)];
}
}
}
may be it will help.
回答3:
I think that both of you problems are due to not well defined/missing autoresizingMask
's or missing auto-layout constraints (whichever you're using).
What UITabBarController
does when hiding the tab bar is to stretch its view
enough to get the its tabBar
outside the screen. Your contained view controllers' views in turn should properly stretch to use the new space or you'll get empty spaces and/or non interactive zones.
Edit:
Just realized that hiding the tab bar is not in the default SDK but in a category I made long time ago.
Anyway stretching UITabBarController
's view frame seems to me the most elegant way to "hide" the tab bar (actually move it away from the screen) as you don't have to deal with subviews or hunt down the tab bar frame directly.
回答4:
So I've rewritten some of the answers written in Objective-C into Swift 3.0 thinking it would work. Here's the code:
func hideTabBar() {
let tabBarControllerView = self.tabBarController?.view
if let tabBarControllerSubviews = tabBarControllerView?.subviews {
for view in tabBarControllerSubviews {
if view is UITabBar {
view.frame = CGRect(
x: view.frame.origin.x,
y: (UIScreen.main.bounds.size.height == 568 ? 568 : 480) + 20,
width: self.view.frame.size.width,
height: self.view.frame.size.height
)
} else {
view.frame = CGRect(
x: view.frame.origin.x,
y: view.frame.origin.y,
width: self.view.frame.size.width,
height: UIScreen.main.bounds.size.height == 568 ? 568 : 480
)
}
}
}
}
func showTabBar() {
let tabBarControllerView = self.tabBarController?.view
if let tabBarControllerSubviews = tabBarControllerView?.subviews {
for view in tabBarControllerSubviews {
if view is UITabBar {
view.frame = CGRect(
x: view.frame.origin.x,
y: (UIScreen.main.bounds.size.height == 568 ? 519 : 431),
width: self.view.frame.size.width,
height: self.view.frame.size.height
)
} else {
view.frame = CGRect(
x: view.frame.origin.x,
y: view.frame.origin.y,
width: self.view.frame.size.width,
height: UIScreen.main.bounds.size.height == 568 ? 519 : 431
)
}
}
}
}
回答5:
Use following code to resolve your problem
Hide :
-(void)hideTabBar:(UITabBarController *)tabbarcontroller
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
float fHeight = screenRect.size.height;
if( UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) )
{
fHeight = screenRect.size.width;
}
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, fHeight, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, fHeight)];
view.backgroundColor = [UIColor blackColor];
}
}
}
Show :
-(void)showTabBar:(UITabBarController *) tabbarcontroller
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
float fHeight = screenRect.size.height - 49.0;
if( UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) )
{
fHeight = screenRect.size.width - 49.0;
}
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, fHeight, view.frame.size.width, view.frame.size.height)];
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, fHeight)];
}
}
}
Use this methods in viewWillAppear and on device rotation methods as per your requirement
来源:https://stackoverflow.com/questions/21456166/ios-7-hide-tabbar-issue