在iOS中显示多个视图的最佳实践 [英] Best practice for displaying multiple views in iOS

查看:107
本文介绍了在iOS中显示多个视图的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个教育应用程序,它将拥有大约3-5个完全不同的页面/屏幕。每个屏幕包含一个谜题,每个谜题独立于所有其他谜题(屏幕)。一旦解决了当前屏幕上的谜题,我想转换到一个新的(随机选择的)屏幕。我会允许多次显示相同的谜题,但是,如果它已经显示之前需要重置。

I'm trying to build an educational app that will have approximately 3-5 completely different pages/screens. Each screen contains one puzzle and each puzzle is independent of all the other puzzles (screens). Once the puzzle on the current screen is solved I'd like to transition to a new (randomly selected) screen. I would allow the same puzzle to be shown multiple times, however, if it had been displayed before it would need to be reset.

我尝试过使用segues但这似乎需要一个UINavigationController,这不是我想要呈现的体验(因为它需要预定义的屏幕层次结构)。

I've tried doing this using segues but that seems to require a UINavigationController which is not the experience I want to present (since it requires a predefined hierarchy of screens).

我认为最佳方法是将每个屏幕视为完全独立的UIViewControllers,对吗?我只是不确定如何协调它们之间的导航/渲染。

I assume the best way to do this is to have each screen as completely separate UIViewControllers, correct? I'm just not sure how to orchestrate the navigation/rendering between them.

我很欣赏你所知道的最佳实践。谢谢!

I'd appreciate whatever best practices you know of. Thanks!

推荐答案

这里有一个可能的选择:

Well here is a possible option:

首先所有如果你想在这些谜题之外的菜单将其作为 UINavigationController中的根视图控制器

First of all if you want a menu outside of these puzzles have that as your root view controller in a UINavigationController.

然后创建一个启动器控制器并在适当时将其添加到导航控制器。这将是一个常规的 UIViewController ,除了在 viewWillAppear 方法中的这个控制器,它选择一个随机数0-5和通过一个开关运行它,并根据数字推送你的5个视图控制器之一。然后当拼图完成时,在导航控制器上调用 popViewController 。现在当它弹回时,将再次调用 viewWillAppear 并随机推送另一个。然后,如果你想随时回到主菜单,只需调用 popToRootViewControllerAnimated 。这应该做你需要的。并且要做到这一点,它没有动画两次要么只有推动动画或只有流行音乐。

Then create a launcher controller and add it to the navigation controller when appropriate. This will be a regular UIViewController except in this controller in the viewWillAppear method have it pick a random number 0-5 and run it through a switch and depending on the number push one of your 5 view controllers. Then when the puzzle is completed call popViewController on the navigation controller. Now when it pops back, viewWillAppear will be called again and randomly push another. Then if you want to go back to the main menu at any time just call popToRootViewControllerAnimated. This should do what you need. And to make it so it doesn't animate twice either only have the push animate or only the pop.

这篇关于在iOS中显示多个视图的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆