【发布时间】:2010-11-03 04:08:20
【问题描述】:
想知道是否有人可以帮助我。我有一个设置,主菜单将主游戏显示为模态视图控制器。此时它也停止播放主菜单音乐。
问题是当游戏视图控制器自行关闭时(例如,当用户退出游戏时)并返回主菜单时,我无法让主菜单音乐再次开始播放。
有什么方法可以让主菜单中的音乐重新开始播放吗?例如,当主游戏关闭时调用的委托方法?
谢谢,
马丁
【问题讨论】:
标签: iphone objective-c uiviewcontroller
想知道是否有人可以帮助我。我有一个设置,主菜单将主游戏显示为模态视图控制器。此时它也停止播放主菜单音乐。
问题是当游戏视图控制器自行关闭时(例如,当用户退出游戏时)并返回主菜单时,我无法让主菜单音乐再次开始播放。
有什么方法可以让主菜单中的音乐重新开始播放吗?例如,当主游戏关闭时调用的委托方法?
谢谢,
马丁
【问题讨论】:
标签: iphone objective-c uiviewcontroller
你可以用 NotificationManager 做到这一点
// set up notification
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playMusic:)
name:@"musicNotification"
object:nil];
// send notification
[[NSNotificationCenter defaultCenter] postNotificationName:@"musicNotification"
object:self];
// clean up notification
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
- (void) playMusic:(NSNotification *) notification
{
// play the music here
if ([[notification name] isEqualToString:@"musicNotification"])
NSLog (@"Received musicNotification!");
}
【讨论】: