隐藏IOS7中的标签栏显示非正式行为
当我使用
时self.tabBarController.tabBar.hidden = YES;
上面的代码隐藏了tabBar,但我的底部视图不会保持交互式
但是当我在导航中推送viewController之前使用它时
someViewController.hidesBottomBarWhenPushed = YES
[self.navigationController pushViewController:someViewController animated:YES];
它隐藏了tabbar以及从底部查看也是交互式的。 但是在这种情况下的问题是,当我们弹出viewController时,它会在tabbar上方显示黑条几秒钟。
答案 0 :(得分:10)
我希望你能得到解决方案。只是为了确保,你有没有尝试
self.edgesForExtendedLayout = UIRectEdgeBottom;
答案 1 :(得分:0)
我认为你们两个问题都是由于没有明确定义/缺少autoresizingMask
或缺少自动布局限制(无论你使用哪个)。
隐藏标签栏时UITabBarController
的作用是拉伸view
足以使其tabBar
在屏幕外。你包含的视图控制器'反过来,视图应适当拉伸以使用新空间,否则您将获得空白区域和/或非交互区域。
修改强>
刚才意识到隐藏标签栏不在默认SDK中,而是在很久以前的category中。
无论如何,拉伸UITabBarController
的视图框架在我看来是最优雅的方式来隐藏"标签栏(实际上将其移离屏幕),因为您不必处理子视图或直接搜索标签栏框架。
答案 2 :(得分:0)
试试这个,如果你想隐藏/显示视图的UITabBarController:
隐藏标签栏:
- (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)];
}
}
}
显示标签栏:
- (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)];
}
}
}
可能会有所帮助。
答案 3 :(得分:0)
所以我把一些用Objective-C编写的答案改写成Swift 3.0,认为它会起作用。这是代码:
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
)
}
}
}
}
答案 4 :(得分:-1)
使用以下代码解决您的问题
隐藏:
-(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];
}
}
}
显示:
-(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)];
}
}
}
根据您的要求在viewWillAppear和设备旋转方法中使用此方法