[英]How can I remove TabBar if I enter one given ViewController
Setting: 设置:
Assume I have 2 TableViewControllers(All in their own NavigationControllers), which contain TypeA&B items correspondingly. 假设我有2个TableViewControllers(All在他们自己的NavigationControllers中),它们相应地包含TypeA和B项。
In any TableView, If I tap "+" button, it will segue to a Add[?]ItemViewController("?" is The Type of Item: A or B).So normally, even if I already in the AddView, I can also switch to another View By tapping Tab Bar Icon, right? 在任何TableView中,如果我点击“+”按钮,它将转换为Add [?] ItemViewController(“?”是项目类型:A或B)。通常,即使我已经在AddView中,我也可以也可以通过点击标签栏图标切换到另一个视图,对吧?
SO How can I inhibit user to switch if they already entered one AddView? 如果他们已经进入一个AddView,我如何禁止用户切换?
Use the Swift code?
使用Swift代码? or just change the storyboard structure?
或者只是改变故事板结构?
Here is the Structure of Main.storyboard: 这是Main.storyboard的结构:
We've done exactly the same in our application.
我们在应用程序中完成了相同的操作。 To hide the default TabBar, simply override the hidesBottomBarWhenPushed method in your parent view controller (or in every view controller in your App)
要隐藏默认TabBar,只需覆盖父视图控制器(或应用程序中的每个视图控制器)中的hidesBottomBarWhenPushed方法
#pragma mark - Overriden UIViewController methods
- (BOOL)hidesBottomBarWhenPushed {
return YES;
}
You can also Hide Tab bar 您还可以隐藏标签栏
// pass a param to describe the state change, an animated flag and a completion block matching UIView animations completion
- (void)setTabBarVisible:(BOOL)visible animated:(BOOL)animated completion:(void (^)(BOOL))completion {
// bail if the current state matches the desired state
if ([self tabBarIsVisible] == visible) return;
// get a frame calculation ready
CGRect frame = self.tabBarController.tabBar.frame;
CGFloat height = frame.size.height;
CGFloat offsetY = (visible)? -height : height;
// zero duration means no animation
CGFloat duration = (animated)? 0.3 : 0.0;
[UIView animateWithDuration:duration animations:^{
self.tabBarController.tabBar.frame = CGRectOffset(frame, 0, offsetY);
} completion:completion];
}
// know the current state
- (BOOL)tabBarIsVisible {
return self.tabBarController.tabBar.frame.origin.y < CGRectGetMaxY(self.view.frame);
}
// illustration of a call to toggle current state
- (IBAction)pressedButton:(id)sender {
[self setTabBarVisible:![self tabBarIsVisible] animated:YES completion:^(BOOL finished) {
NSLog(@"finished");
}];
}
You can set the UIViewController.hidesBottomBarWhenPushed instead: 您可以设置UIViewController.hidesBottomBarWhenPushed:
DetailViewController *detailViewController = [[DetailViewController alloc] init];
detailViewController.hidesBottomBarWhenPushed = YES;
[[self navigationController] pushViewController:detailViewController animated:YES];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.