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

2.4k views Asked by At

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

2

There are 2 answers

1
vikingosegundo On BEST ANSWER

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

0
christian On

I think you can do it adding it on top of application window(which is UIWindow, subclass of UIView)

UIView *myView = /* <- Your custom view */;
UIWindow *currentWindow = [UIApplication sharedApplication].keyWindow;
[currentWindow addSubview:myView];

Took the code from https://stackoverflow.com/a/21850538/1947419

Or you can add to UITabBarController.view directly since it's UIView spanning entire screen.

You need to make custom view for it though.