【发布时间】:2019-01-10 23:37:57
【问题描述】:
在使用我的应用程序期间,用户应该能够启动、停止、转发背景音乐。 (跨越几个 UIViewControllers)。为此,我将我的 MusicPlayer 设置为单例 (NSObject)。如果我在每个视图中为它自己创建控件,它就可以工作,但我想要的基本上是一个视图,它处理音乐播放器类并且一直存在。用户还应该能够通过向左或向右滑动来“隐藏”和“显示”视图。因此,如果它被隐藏并且我更改了我的视图控制器,它也应该隐藏在新的视图控制器中,并且音乐不应该被中断。
我在我的主视图控制器中尝试了这个,它可以工作:
UIView * playerView = [[UIView alloc] initWithFrame:CGRectMake(0, 300, self.view.bounds.size.width, 44)];
playerView.backgroundColor = [UIColor redColor];
[[[[UIApplication sharedApplication] delegate] window] addSubview:playerView];
有没有办法在 ApplicationDelegate 中做到这一点?
【问题讨论】:
标签: ios iphone xcode singleton audio-player