Chr*_*ris 10 iphone objective-c uinavigationcontroller uitabbar
我有一个导航控制器.对于其中一个视图,我想隐藏底部标签栏,以便获得最大可能的屏幕空间.要做到这一点,我有:
- (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;
}
Run Code Online (Sandbox Code Playgroud)
但是对于我推动堆栈的下一个视图,我希望标签栏重新出现.有没有办法做到这一点?
And*_*sak 12
从iOS5开始,有一种非常简单的方法可以实现这一点.它与Deepak基本上是相同的方法,但动画中没有任何工件 - 一切看起来都像预期的那样.
在init上,设置
self.hidesBottomBarWhenPushed = YES;
Run Code Online (Sandbox Code Playgroud)
就像你上面一样.什么时候把新控制器推到堆栈上,就像这样简单:
self.hidesBottomBarWhenPushed = NO;
UIViewController *controller = [[[BBListingController alloc] init] autorelease];
[self.navigationController pushViewController:controller];
self.hidesBottomBarWhenPushed = YES;
Run Code Online (Sandbox Code Playgroud)
在按下控制器后将值重置为YES非常重要,以便在用户点击"返回"按钮并且视图重新进入视图时重新隐藏栏.
我已经解决了这个问题:
几乎所有的ViewControllers都是BaseViewController的子代.
所以,例如:
class BaseVC: UIViewController {
final override var hidesBottomBarWhenPushed: Bool {
get {
if navigationController?.viewControllers.last == self {
return prefersBottomBarHidden ?? super.hidesBottomBarWhenPushed
} else {
return false
}
} set {
super.hidesBottomBarWhenPushed = newValue
}
}
private(set) var prefersBottomBarHidden: Bool?
}
Run Code Online (Sandbox Code Playgroud)
只需在ViewController中覆盖变量"prefersBottomBarHidden",其中应隐藏BottomBar:
override var prefersBottomBarHidden: Bool? { return true }
Run Code Online (Sandbox Code Playgroud)
自从提出这个问题以来已经有一段时间了,但这些答案都没有使用Storyboard segues 解决。事实证明这很容易:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "MyViewControllerIdentifier" {
// Hide the tabbar during this segue
hidesBottomBarWhenPushed = true
// Restore the tabbar when it's popped in the future
DispatchQueue.main.async { self.hidesBottomBarWhenPushed = false }
}
}
Run Code Online (Sandbox Code Playgroud)
人们可以让它重新出现,但这会导致动画不正确。页面位于左侧,底部栏位于右侧。所以这可能不是您想要的行为。但在同一个控制器中,请self.hidesBottomBarWhenPushed = NO;在推入下一个视图控制器之前执行此操作。
| 归档时间: |
|
| 查看次数: |
8223 次 |
| 最近记录: |