【问题标题】:Present a View Controller modally when selected in Tab Bar Controller在选项卡栏控制器中选择时以模态方式呈现视图控制器
【发布时间】:2014-10-27 18:33:12
【问题描述】:

我有这个非常标准的标签栏控制器设置:

UIViewController *homeViewController = [[PLOTHomeViewController alloc] init];
UIViewController *upcomingViewController = [[PLOTUpcomingViewController alloc] init];
UIViewController *checkInViewController = [[PLOTCheckInViewController alloc] init];
UIViewController *watchlistViewController = [[PLOTWatchlistViewController alloc] init];
UIViewController *profileViewController = [[PLOTProfileViewController alloc] init];

PLOTNavigationController *homeNavVC = [[PLOTNavigationController alloc] initWithRootViewController:homeViewController];
PLOTNavigationController *upcomingNavVC = [[PLOTNavigationController alloc] initWithRootViewController:upcomingViewController];
PLOTNavigationController *checkInNavVC = [[PLOTNavigationController alloc] initWithRootViewController:checkInViewController];
PLOTNavigationController *watchlistNavVC = [[PLOTNavigationController alloc] initWithRootViewController:watchlistViewController];
PLOTNavigationController *profileNavVC = [[PLOTNavigationController alloc] initWithRootViewController:profileViewController];

self.tabBarController = [[PLOTTabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:homeNavVC, upcomingNavVC, checkInNavVC, watchlistNavVC, profileNavVC, nil];

但是,我试图弄清楚,当用户选择中间选项卡 (checkInViewController) 时,我可以如何以模态方式(全屏)呈现该视图控制器?我可能会在那个 VC 的 viewDidAppear 方法中想象一些东西,但我不确定你是否可以模态地展示自己,如果你是 VC?最好的方法是什么?

【问题讨论】:

  • 在 checkInView 的 init 方法中设置 self.hidesBottomBarWhenPushed 是否满足您的需要?
  • @neal 真是太棒了,我想它给了我最终的结果,但我想我不能像模态一样“忽略”它......或者我可以吗? (而且它没有动画)

标签: ios objective-c


【解决方案1】:

你可以使用

[self presentViewController:checkInViewController animated:YES completion:nil];

然后在目标视图控制器的viewWillAppear:中隐藏标签和导航栏

-(void)viewWillAppear:(BOOL)animated {
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    [self.tabBarController.tabBar setHidden:YES];
}

【讨论】:

  • 但我应该在什么时候运行它?我希望当用户在 tabbarcontroller 中选择该选项卡栏项时发生这种情况
  • 我似乎有点误解了你的问题——当用户选择 checkInViewController 时,你希望显示视图控制器并隐藏顶部和底部的导航/标签栏?
  • 是的,几乎完全像 Instagram 应用一样,即。您点击选项卡,全屏模式覆盖所有内容
猜你喜欢
  • 2017-11-15
  • 1970-01-01
  • 2021-07-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-20
相关资源
最近更新 更多