How to persist a slide-out sidebar menu through en

2020-08-01 07:51发布

问题:

Is there an established solution for how to create and persist a slide out sidebar menu (like on Facebook, or Spotify) so that it appears on any view in your iOS application? I've tried using MMDrawerController, but once i segue from the initial view, I lose the sidebar. I assume this is because I'm transitioning the entire viewController, and not just changing the centerViewController.

Of note, I am using a storyboard in my project, and would like to continue if possible.

回答1:

If I have a GUI element that I want to persist permanently (or appear and disappear but be shared by multiple view controllers) then I create a root view controller and add the persistent gui elements to it and add a container view as a subclass of the RVC's main view which covers the entire size of the screen.

Then what ordinarily would have been your app's rvc is embedded within this container view.

In the example I've posted there is a UILabel on top of the container which of course could be anything (including a whole hierarchy of views, or another container view with another view controller embedded with in it, whatever you want). You can make it appear or disappear as need be throughout the rest of the program either by creating/destroying it as needed, or fading the alpha to/from 0, or changing the x.y co-ordinates to animate it onto/off of the screen etc.