Search code examples
iosswiftuitoolbarpodcastuitabview

How do I make a view that stays onscreen when the main view segues?


How do I make a view that does not appear to be reloaded (stays onscreen) every time a view segues? Like the audio controls in Apple's iOS podcast app. See pictures to see audio controls I am referencing.

How do I do it in storyboard?

enter image description here


Solution

  • What you are referring to is usually called "mini player", you'll find it in many other apps too.

    The technique you should use is called "UIViewController Containment", in storyboards it is accessible as "Container View" and "Embed Segues".

    A typical storyboard might look like:

    • The root view controller has two Container View added to it's view.
    • The container views have segues to view controllers. In the view
    • controller that relates to the lower one, setup the mini player.
    • The view controller of the upper container embed in a navigation controller and a tab view controller.

    screen

    This will create the view controller hierarchy.

    To implement the player itself create a player class that you instantiate in the app delegate and pass it to a property on the root vc. from there pass it to the mini player view controller and to the upper view controller, that will contain the list of songs/podcast/... to select from. At selection pass hat song to the player class.


    I posted an example app at GitHub: https://github.com/vikingosegundo/HearThisMiniplayer

    screen