我有一个UIViewController,我称之为根,它表示(通过模态段)另一个UIViewController (firstChild),它表示(同样通过模态段)一个UINavigationController (topChild)。在top child中,我执行以下操作:
[root dismissViewControllerAnimated:NO completion:^{
[root performSegueWithIdentifier:@"ToNewFirstChild" sender:self];
}];
在iOS 7中,这样做的效果是topChild会一直显示在屏幕上,直到完成对newFirstChild的分段,然后就会显示newFirstChild (由根用户显示)。我喜欢这样。
在iOS 8中,效果是立即从屏幕上删除topChild,短暂地显示firstChild,然后删除,留下根显示,直到段完成,然后显示newFirstChild (由根显示)。我不喜欢那样。
如果我选择对dismissViewControllerAnimated:completion:
进行动画处理,将会出现以下结果:在iOS 7中,topChild会随动画一起消失,而不会显示firstChild (如文档中所述),在段完成之前,根将一直显示;在iOS8中,topChild会立即从屏幕上移除,留下firstChild,它会随动画一起消失(与文档相反!),在段完成之前,根将一直显示。
你知道如何在iOS 8中获得在iOS 7中产生的效果(有或没有动画)吗?我遗漏了什么?
发布于 2014-11-13 06:54:21
您在这里处理的问题是,您试图调用视图控制器的dismissViewControllerAnimated:completion
的完成块中的一个方法,而您正在忽略该方法(并因此取消分配),因此出现了零星且不可预测的行为。
我推荐使用像NSNotificationCenter
这样的工具在视图控制器被关闭时发布通知,并在父(根)控制器中保留一个可以接收通知的处理程序。
在根视图控制器中,在某个地方调用它(也许在prepareForSegue
中?):
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(topChildWasDismissed:)
name:@"TopChildDismissed"
object:nil];
您还需要在根VC中使用一个处理程序方法:
- (void)topChildWasDismissed {
[self performSegueWithIdentifier:@"ToNewFirstChild" sender:self];
}
然后在你最上面的孩子中:
[self dismissViewControllerAnimated:YES completion:^(void) {
[[NSNotificationCenter defaultCenter] postNotificationName:@"TopChildDismissed" object:self];
}];
https://stackoverflow.com/questions/26898129
复制相似问题