0

I am working on an app that has an audio player. The audio player is working fine I am using JukeBox library to play the audio, the problem is when the user navigates through the application outside the view controller that contains the audio player, I need to open for him a view from below that stays on the screen playing the audio wherever he navigates in the app. I have no idea how to do that any help please.

3 Answers3

0

You can either:

1. Add this view to your rootViewController if you have that was set in the AppDelegate, or

2. Add this view to your UIApplication.shared.keyWindow as a subview.

cohen72
  • 2,830
  • 29
  • 44
0

You can put button instead of the view in the code below.

let persistentView = UIView(frame: CGRect(x:0 ,y:0 ,width:100 ,height:100))
persistentView.backgroundColor = UIColor.red
UIApplication.sharedApplication().keyWindow?.addSubview(persistentView)

Hope this helps!

Mohamad Bachir Sidani
  • 2,077
  • 1
  • 11
  • 17
0

Rethink the navigation of your app. I suggest creating a view controller that handles the audio player view and acts as parent for your other controllers. You can for instance embed a UINavigation controller, so your parent controller stays on screen at all times while you can still navigate your app using the push and pop methods of UINavigationController.

To set up your parent view controller in storyboard drag a container view from the object library into your parent view controller. Then ctrl drag from from the container view to a navigation controller and select embed.

enter image description here

    // to access the navigation controller in the parent
    var embeddedNavigationController: UINavigationController? {
        return childViewControllers.first as? UINavigationController
    }

    // to access the parent from other controllers inside your navigation controller
    var parentViewController: ParentViewController? {
        return navigationController?.parent as? ParentViewController        
    }

    // or simply make the parents audio view controls static functions
pkorosec
  • 676
  • 8
  • 13