I am developing a game, and I would like to transition between several views, e.g. Menu Screen, Game Screen, Game Over Screen etc. What would be the easiest way of doing this? I’m not sure if I should use a view stack as the order that the views are shown is not always reversed.
Share
I assume by “view stack” you mean a UINavigationController?
The easiest way is to keep references to all of the view controllers somewhere, for example I see people use the application delegate a lot, so your application delegate’s class extension would look a little like:
Assume rootViewController just controls a container view for the rest of the app (You would probably actually be well served putting all this logic into the root view controller though…)
Now anytime you need to show a certain screen, call a method like:
You can now write methods that are named more memorably like
-switchToGameOverScreenThis basic pattern of view navigation is roughly found in
UITabBarControllerand often in views controlled byUISegmentedControls.Hopefully this helps!