在当前视图控制器下显示新的视图控制器
Present new view controller underneath current view controller
我正在尝试展示一个新的视图控制器,它通过关闭呈现视图控制器并让呈现的视图控制器 'already' 位于呈现视图控制器的后面,与模态视图的方式大致相同控制器是 presented/dismissed.
有没有办法通过仅显示视图控制器来实现此目的,或者我是否必须以某种方式事先显示视图控制器,然后将其隐藏在下面,然后关闭显示的视图控制器?
您确实可以通过 "hiding" 您要显示的第一个视图控制器下方的第二个视图控制器来做到这一点。 UINavigationController
免费为您提供所需的一切。
在显示模态视图的视图控制器中使用以下(伪)代码:
FirstVC *first = [[FirstVC alloc] init]; // this VC is shown first
SecondVC *second = [[FirstVC alloc] init]; // this VC that hides beneath the other
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:second];
[nav pushViewController:first animated:NO];
[self presentViewController:nav animated:YES completion:nil];
然后,每当你想关闭第一个视图控制器时,你可以调用:
[self.navigationController popViewControllerAnimated:YES];
请注意,您仍然需要关闭模态视图。
我正在尝试展示一个新的视图控制器,它通过关闭呈现视图控制器并让呈现的视图控制器 'already' 位于呈现视图控制器的后面,与模态视图的方式大致相同控制器是 presented/dismissed.
有没有办法通过仅显示视图控制器来实现此目的,或者我是否必须以某种方式事先显示视图控制器,然后将其隐藏在下面,然后关闭显示的视图控制器?
您确实可以通过 "hiding" 您要显示的第一个视图控制器下方的第二个视图控制器来做到这一点。 UINavigationController
免费为您提供所需的一切。
在显示模态视图的视图控制器中使用以下(伪)代码:
FirstVC *first = [[FirstVC alloc] init]; // this VC is shown first
SecondVC *second = [[FirstVC alloc] init]; // this VC that hides beneath the other
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:second];
[nav pushViewController:first animated:NO];
[self presentViewController:nav animated:YES completion:nil];
然后,每当你想关闭第一个视图控制器时,你可以调用:
[self.navigationController popViewControllerAnimated:YES];
请注意,您仍然需要关闭模态视图。