环境:
假设我有2个TableViewControllers(All在他们自己的NavigationControllers中),它们相应地包含TypeA和B项。
在任何TableView中,如果我点击" +"按钮,它会转到添加[?] ItemViewController("?"是项目类型:A或B)。所以,即使我已经在AddView中,我也可以切换到另一个查看通过点击标签栏图标,对吗?
如果他们已经输入了一个AddView,我怎么能禁止用户切换?
使用 Swift 代码?或者只是改变故事板结构?
这是Main.storyboard的结构:
答案 0 :(得分:3)
我们在申请中完成了相同的工作。隐藏默认值 TabBar,简单地覆盖你的hidesBottomBarWhenPushed方法 父视图控制器(或应用程序中的每个视图控制器)
#pragma mark - Overriden UIViewController methods
- (BOOL)hidesBottomBarWhenPushed {
return YES;
}
您还可以隐藏标签栏
// 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");
}];
}
您可以设置UIViewController.hidesBottomBarWhenPushed:
DetailViewController *detailViewController = [[DetailViewController alloc] init];
detailViewController.hidesBottomBarWhenPushed = YES;
[[self navigationController] pushViewController:detailViewController animated:YES];