创建模态 UIViewController 堆栈的替代方案?

发布于 2024-11-09 14:24:43 字数 431 浏览 0 评论 0原文

我遇到一种情况,用户通过一系列“级别”取得进展。每个级别都有自己的 UIViewController。现在,我只是简单地介绍下一个级别,如下所示:

// in level 1 view controller, for example, here's how we go to level 2
[self presentModalViewController:level2VC animated:YES];

这很好也很简单,但显然它会产生一个非常大的 UIViewController 堆栈。理想情况下,我想对下一个级别的 UIViewController 进行良好的视觉过渡(例如交叉溶解),然后释放最后一个以节省内存,但我认为这会导致不稳定,因为我在这种方法中会释放父视图控制器。

那么最好的方法是什么?

谢谢!

I have a situation where a user progresses through a series of "levels". Each level has it's own UIViewController. Right now, I simply present the next level like this:

// in level 1 view controller, for example, here's how we go to level 2
[self presentModalViewController:level2VC animated:YES];

This is nice and easy, but obviously it results in a really large stack of UIViewControllers. Ideally, I'd like to do a nice visual transition (like cross-dissolve) to the next level's UIViewController and then release the last one to conserve memory, but I think that'll cause instability since I'd be releasing the parent view controller in this approach.

What is the best approach then?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

信仰 2024-11-16 14:24:43

这就是 UINavigationController 的构建目的! 类参考

This is what a UINavigationController was built for! Class Reference

被翻牌 2024-11-16 14:24:43

UINavigationController 是您所描述的 UI 类型的常见习惯用法。

您可以通过执行:pushViewController:animated:来推送一个新的视图控制器,这也提供了您正在寻找的过渡效果。

无论如何,请记住,这正是用于“导航”:即来回移动。所以,这不仅仅是前进,除非你通过隐藏“后退”按钮[self.navigationItem setHidesBackButton:YESanimated:YES]来自定义导航栏。

此外,所有 UIViewControllera 都保存在内存中(始终),并且仅在内存不足的情况下 (-[didReceiveMemoryWarning][1]),“受控”视图才会会自动释放,从而恢复内存。如果发生这种情况,您将需要确保能够再次加载视图,以防用户导航回来。

如果您真的关心内存(尽管我认为这不应该是问题),您甚至可以考虑“弹出”(即删除)当前控制器,然后再推动下一个控制器。这将承受非常“扁平”的控制器层次结构。

UINavigationController is the common idiom for the kind of UI you are describing.

You push a new view controller by executing: pushViewController:animated:, which also provides for the transition effect you are looking for.

Keep in mind, anyway, that this is meant exactly for "navigating" : i.e., moving back and forth. So, it is not just going forward, unless you customize the navigation bar by hiding the "back" button [self.navigationItem setHidesBackButton:YES animated:YES].

Furthermore, all the UIViewControllera are kept in memory (always) and only in case of low memory conditions (-[didReceiveMemoryWarning][1]) the "controlled" views will be automatically released, thus recovering memory. If this happens, you will need to ensure you are able to load again the views in case the user navigates back.

If you are really concerned about memory (although I think that it should not be a problem), you could even think of "poppping" (i.e., removing) the current controller, before pushing the next one. This would endure a very "flat" hierarchy of controllers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文