我有一个导航 Controller 堆栈,其中包含不同的可能 Controller 。
我想根据我推送到导航 Controller 的下一个 View ,在需要时以模态方式呈现一个 View Controller 。 (您可以将其视为用户登录验证屏幕......在移动到下一个屏幕之前验证用户。)
我能够成功地做到这一点
UIApplication.sharedApplication().keyWindow?.rootViewController?.presentViewController(contactPicker, animated: true, completion: nil)
并在我需要用
解雇时解雇它UIApplication.sharedApplication().keyWindow?.rootViewController?.dismissViewControllerAnimated(false, completion: {
self.navigationController.pushViewController(myNewVC, animated: true)
})
我能够做到,但是从模态呈现的 View 到我的 (myNewvC) 新推送的下一个 View 的过渡并不完全是我想要的。当 View 关闭发生时,在我移动到下一个 View 之前,我可以看到我的来电屏幕一秒钟。我不想看到那个屏幕。可能吗?
(我也不想在导航堆栈中添加验证屏幕,因为该屏幕的目的不是导航堆栈的一部分)。
最佳答案
Apple 恰好在此处添加了完成 block ,以保护您免受未捕获的异常的影响,因为您想要做的事情可能会导致一个,因为您不能同时执行两个动画,也许有一些建议的解决方案:
尝试显示新 Controller ,然后在完成后将前一个 Controller 隐藏在完成 block 中(这样当用户关闭新 Controller 时,他将看不到前一个 Controller ),例如 假设你现在在 VC1 中,你想关闭它并显示 VC2,你可以在 objective-c 中使用下面的代码
[self presentViewController:VC2 animated:YES completion:^{
[self dismissViewControllerAnimated:YES completion:nil];
}];
swift
self.presentViewController(VC2, animated: true) { () -> Void in
self.dismissViewControllerAnimated(true, completion: nil)
}
或者您可以忽略它,如果用户不会关闭新 Controller ,那么他将永远不会看到旧 Controller ,但我认为这不会节省内存,因为 Controller 会卡在内存中。
关于iOS:关闭 View Controller 并推送新 View 而不在导航堆栈中显示当前 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35840209/