我有一个UITabBarController
默认视图控制器是UINavigationController
. 当我在UINavigationController
.
我试过添加:
delegate.tabBarController.hidesBottomBarWhenPushed = YES;
在UINavigationController
我推动观点之前,但这似乎并没有奏效。
关于我应该做什么或者是否有可能的任何提示?提前致谢!
我有一个UITabBarController
默认视图控制器是UINavigationController
. 当我在UINavigationController
.
我试过添加:
delegate.tabBarController.hidesBottomBarWhenPushed = YES;
在UINavigationController
我推动观点之前,但这似乎并没有奏效。
关于我应该做什么或者是否有可能的任何提示?提前致谢!
这个更好:
viewController.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:viewController animated:YES];
您必须在要推入视图的控制器上设置 hidesBottomBarWhenPushed = YES ...
使用情节提要时,它易于设置视图控制器,它将在推送时隐藏标签栏,在目标视图控制器上只需选中此复选框:
我已经弄清楚如何解决这个问题,我遇到了同样的问题,但 Apple 还在名为“The Elements”的示例中告诉我们如何做到这一点(http://developer.apple.com/library/ ios/#samplecode/TheElements/Introduction/Intro.html )
请参阅下面的函数以了解如何执行此操作,将其添加到要推送的视图的 init 函数中!
-(id) init {
if(self = [super init]) {
self.hidesBottomBarWhenPushed = YES;
}
return self;
}
它会自动隐藏标签栏,就像你 iPhone 上的照片应用一样。当您返回时,父视图将再次显示标签栏。
祝你好运
我已经尝试了大多数建议的解决方案。最后,他们都没有为我工作。
hideTabBarWhenPushed 不仅为下一个推送的视图控制器隐藏标签栏,还为所有推送的视图控制器隐藏标签栏。对于那些我确实希望标签栏控制器重新出现的人。
Orafaelreis 的解决方案(见上文)似乎最适合。但他的尝试只适用于严格的纵向,甚至不适用于倒置。所以我不得不修补它。这是我最终得到的:
#define kTabBarHeight 49 // This may be different on retina screens. Frankly, I have not yet tried.
- (void) hideTabBar:(BOOL)hide {
// fetch the app delegate
AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
// get the device coordinates
CGRect bounds = [UIScreen mainScreen].bounds;
float width;
float height;
// Apparently the tab bar controller's view works with device coordinates
// and not with normal view/sub view coordinates
// Therefore the following statement works for all orientations.
width = bounds.size.width;
height = bounds.size.height;
if (hide) {
// The tab bar should be hidden too.
// Otherwise it may flickr up a moment upon rotation or
// upon return from detail view controllers.
[self.tabBarController.tabBar setHidden:YES];
// Hiding alone is not sufficient. Hiding alone would leave us with an unusable black
// bar on the bottom of the size of the tab bar.
// We need to enlarge the tab bar controller's view by the height of the tab bar.
// Doing so the tab bar, although hidden, appears just beneath the screen.
// As the tab bar controller's view works in device coordinations, we need to enlarge
// it by the tab bar height in the appropriate direction (height in portrait and width in landscape)
// and in reverse/upside down orientation we need to shift the area's origin beyond zero.
switch (delegate.tabBarController.interfaceOrientation) {
case UIInterfaceOrientationPortrait:
// Easy going. Just add the space on the bottom.
[self.tabBarController.view setFrame:CGRectMake(0,0,width,height+kTabBarHeight)];
break;
case UIInterfaceOrientationPortraitUpsideDown:
// The bottom is now up! Add the appropriate space and shift the rect's origin to y = -49
[self.tabBarController.view setFrame:CGRectMake(0,-kTabBarHeight,width,height+kTabBarHeight)];
break;
case UIInterfaceOrientationLandscapeLeft:
// Same as Portrait but add the space to the with but the height
[self.tabBarController.view setFrame:CGRectMake(0,0,width+kTabBarHeight,height)];
break;
case UIInterfaceOrientationLandscapeRight:
// Similar to Upside Down: Add the space and shift the rect. Just use x and with this time
[self.tabBarController.view setFrame:CGRectMake(0-kTabBarHeight,0,width+kTabBarHeight,height)];
break;
default:
break;
}
} else {
// reset everything to its original state.
[self.tabBarController.view setFrame:CGRectMake(0,0,width,height)];
[self.tabBarController.tabBar setHidden:NO];
}
return;
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
// It is important to call this method at all and to call it here and not in willRotateToInterfaceOrientation
// Otherwise the tab bar will re-appear.
[self hideTabBar:YES];
// You may want to re-arrange any other views according to the new orientation
// You could, of course, utilize willRotateToInterfaceOrientation instead for your subViews.
}
- (void)viewWillAppear: (BOOL)animated {
// In my app I want to hide the status bar and navigation bar too.
// You may not want to do that. If so then skip the next two lines.
self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
[self hideTabBar: YES];
// You may want to re-arrange your subviews here.
// Orientation may have changed while detail view controllers were visible.
// This method is called upon return from pushed and pulled view controllers.
return;
}
- (void)viewWillDisappear: (BOOL)animated {
// This method is called while this view controller is pulled
// or when a sub view controller is pushed and becomes visible
// Therefore the original settings for the tab bar, navigation bar and status bar need to be re-instated
[self hideTabBar:NO];
// If you did not change the appearance of the navigation and status bar in viewWillAppear,
// then you can skip the next two statements too.
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
return;
}
内嵌注释应解释每个语句的推理。不过,可能有更聪明的编码方式。
隐藏状态栏和导航栏也有一个副作用,我不想对你们隐藏。1. 当从这个导航控制器返回到调用导航控制器时,调用控制器上的状态栏和导航栏会重叠,直到设备旋转一次或直到另一个选项卡出现后再次选择相关选项卡。2. 当调用视图控制器是一个表格视图并且当设备在返回表格时处于横向模式时,表格以适合横向的方向显示,但它的布局就像它是纵向的一样。左上角很好,但一些表格单元格和标签栏隐藏在屏幕下方。右侧有一些空闲空间。这也可以通过再次旋转设备来解决。
一旦找到解决这些小但令人讨厌的错误的方法,我会及时通知您。
以下是如何让它发挥作用:
在Application Delegate
您创建UITabBarController
. 然后在特定选项卡中创建一个UINavigationController
具有根控制器的视图控制器作为您想要的视图控制器。然后将其插入UINavigationController
到“ viewControllers ”数组中UITabBarController
。像这样:
ViewControllerForTab1 *tab1Controller = [[ViewControllerForTab1 alloc] initWithNibName:@"ViewControllerForTab1"];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:tab1Controller];
[tab1Controller release];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects: navController, nil];
[navController release];
[self.window addSubView:tabBarController.view];
这样,您可以在其中的任何视图控制器中将“ hidesBottomBarWhenPushed
”属性设置为“” ,它将隐藏.YES
UINavigationController
UITabBar
希望有帮助!
我将在这里给出我的解决方案:
#define FRAME_HIDDEN CGRectMake(0, 0, 768, 1073) //1073 = 1024 (screen) + 49 (UITabBar)
#define FRAME_APPEAR CGRectMake(0, 0, 768,1024)
-(void) setHidden: (BOOL) hidden{
CGRect frame = (hidden)? FRAME_HIDDEN : FRAME_APPEAR;
[self.tabBarController.view setFrame:frame];
[self.tabBarController.tabBar setHidden:hidden];
}
在需要的地方调用“setHidden”方法!我使用这个和“单例模式”,然后我的子视图可以在他的 Superview 中隐藏 UITabBar
事实证明,如果您设置视图hidesBottomBarWhenPushed:YES
,它会在视图出现时隐藏栏(对我来说是这样)。我将它分配给UITabBarController
,当您考虑它时,这并没有多大意义。
[self.view hidesBottomBarWhenPushed:YES];
[super pushViewController:viewController animated:animated];
在第一个 UIViewControllerFirstItemViewController
@IBAction func pushToControllerAction(sender: AnyObject) {
self.hidesBottomBarWhenPushed = true
self.performSegueWithIdentifier("nextController", sender: self)
}
在接下来的 UIViewControllerExampleViewController
override func willMoveToParentViewController(parent: UIViewController?) {
if parent == nil {
var viewControllers = self.navigationController!.viewControllers
if ((viewControllers[viewControllers.count - 2]).isKindOfClass(FirstItemViewController.self)) {
(viewControllers[viewControllers.count - 2] as! FirstItemViewController).hidesBottomBarWhenPushed = false
}
}
}
hidesBottomBarWhenPushed
在要隐藏的控制器中使用。
隐藏所有控制器放入prepare for segue
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
segue.destination.hidesBottomBarWhenPushed = true
}