Make UIViewController a singleton?

前端 未结 3 1437
南旧
南旧 2020-12-20 21:33

During the use of my app, the user should be able to start, stop, forward background music. (Across several UIViewControllers). For this, I made my MusicPlayer a singleton (

3条回答
  •  温柔的废话
    2020-12-20 22:05

    If you use a container view controller (e.g. UINavigationController), you then have all the view controllers switching between one another, and on top of the container you can add your MusicPlayer controls (easiest way would be for it to have the same parent as the navigation controller), that way it's created only once and it doesn't depend on what views are displayed under it.

提交回复
热议问题