使用 hidesBottomBarWhenPushed 时,我希望当我推送另一个视图时标签栏重新出现
我有一个导航控制器。对于其中一个视图,我想隐藏底部选项卡栏,因此它可以获得最大可能的屏幕空间。为此,我有:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.hidesBottomBarWhenPushed = YES; // To hide the tab bar
}
return self;
}
但是对于我推入堆栈的下一个视图,我希望标签栏重新出现。有办法做到这一点吗?
I have a navigation controller. For one of the views i want to hide the bottom tab bar, so it gets the max possible screen real estate. To do this, i have:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.hidesBottomBarWhenPushed = YES; // To hide the tab bar
}
return self;
}
But for the next view that i push on the stack, i want the tab bar to reappear. Is there a way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
从 iOS5 开始,有一种非常简单的方法可以实现这一点。它本质上与 Deepak 的方法相同,但动画中没有任何伪影 - 一切看起来都符合预期。
在初始化时,
按照上面的设置进行设置。当需要将新控制器推送到堆栈上时,非常简单:
在推送控制器后将值重置为 YES 很重要,以便在用户点击“后退”按钮并且视图出现时重新隐藏栏回到视野中。
As of iOS5, there's a very easy means of accomplishing this. It's essentially the same method as Deepak, but there aren't any artifacts with the animation - everything looks as expected.
On init, set
just as you have above. When it's time to push the new controller on the stack, it's as simple as:
It's important to reset the value to YES after the controller has been pushed in order to re-hide the bar when the user taps the Back button and the view comes back into view.
我已经这样解决了这个问题:
几乎所有我的 ViewController 都是 BaseViewController 的子级。
因此,例如:
只需在 ViewController 中覆盖变量“prefersBottomBarHidden”,其中应隐藏 BottomBar:
I'm have solved this problem like that:
Almost all my ViewControllers are children of BaseViewController.
So, example:
Just override variable "prefersBottomBarHidden" in ViewController where BottomBar should be hidden:
自从提出这个问题以来已经有一段时间了,但是这些答案都没有解决使用故事板转场的问题。事实证明这很简单:
It's been a while since this question was asked, but none of these answers address using Storyboard segues. It turns out to be pretty easy:
人们可以让它重新出现,但这会导致动画不正确。页面位于左侧,底部栏位于右侧。所以这可能不是您想要的行为。但在同一个控制器中,在推入下一个视图控制器之前执行
self.hidesBottomBarWhenPushed = NO;
。One can make it reappear but it will result in an incorrect animation. Page comes in left and the bottom bar right. So it is probably not the behavior you want. But in the same controller, do
self.hidesBottomBarWhenPushed = NO;
before pushing the next view controller in.案例一:
要在某个 UIVIewController 中隐藏 UITabbarController,例如在调用 self.performSegueWithIdentifier("Identifier", sender: self) 时,必须在此之前设置 self.hidesBottomBarWhenPushed = true< /代码> 标志。在
self.hidesBottomBarWhenPushed = false
标志之后。但我们必须明白,通过一个 UIViewController,UITabbarController 将重新出现,如果您需要将 UITabbarController 与单个 UIViewControler 一起使用,它将不会产生正确的结果。情况二:
要在某个 UIVIewController 中隐藏 UITabbarController,然后弹出 UITabbarController,有必要在调用
self.performSegueWithIdentifier("nextController", sender: self)
时设置self.hidesBottomBarWhenPushed = true
在该方法之前。另外,方法中的willMoveToParentViewController(parent: UIViewController?)
应按照代码示例中所示进行配置。Swift 3 代码中:
Case one:
To hide UITabbarController in a cetain UIVIewController, for example while calling
self.performSegueWithIdentifier("Identifier", sender: self)
, it is necesssary prior to to that, setself.hidesBottomBarWhenPushed = true
flag. And afterself.hidesBottomBarWhenPushed = false
flag. But we have to understad that through one UIViewController, UITabbarController will re-appear and, in case if you need to use UITabbarController with single UIViewControler, it wont yield right result.Case Two:
To hide UITabbarController in a certain UIVIewController, after which a UITabbarController should be popped, it is necessary, for example, while calling
self.performSegueWithIdentifier("nextController", sender: self)
, to setself.hidesBottomBarWhenPushed = true
before the method. AlsewillMoveToParentViewController(parent: UIViewController?)
in the method should be configured as it shown in the code example.Swift 3 code:
在根视图控制器“A”(显示 tabBar)中,当需要显示另一个不需要 tabBar 的视图控制器“B”时:
在视图控制器 B 中,当需要显示第三个视图控制器 C 时(再次想要tabBar):
In a root view controller "A" (which is showing the tabBar), when it comes time to show another view controller "B" where no tabBar is wanted:
In view controller B, when it comes time to show a third view controller C (tabBar wanted again):