gpt4 book ai didi

iphone - 当有人给您打电话/发短信时暂停游戏

转载 作者:搜寻专家 更新时间:2023-10-30 19:59:17 24 4
gpt4 key购买 nike

我想在我的应用程序上实现这个功能,但我似乎无法弄清楚如何使用这行代码。

- (void)applicationWillResignActive:(UIApplication *)application {
//our app is going to loose focus since there is an incoming call
[self pauseGame];
}

- (void)applicationDidBecomeActive:(UIApplication *)application{
//the user declined the call and is returning to our app
[self resumeGame];
}

我读到这必须放在 appdelegates 中,但我似乎无法弄清楚当游戏当前在 viewcontroller 中时如何调用我的暂停操作。

谢谢。

最佳答案

您可以将消息发送给您的 View Controller ,而不是将消息发送给自己(应用委托(delegate))。

例如,如果您的应用委托(delegate)有一个名为“gameViewController”的主游戏 View Controller 属性(其中实现了暂停和恢复方法):

- (void)applicationWillResignActive:(UIApplication *)application {
// our app is going to loose focus since there is an incoming call
[self.gameViewController pauseGame];
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
// the user declined the call and is returning to our app
[self.gameViewController resumeGame];
}

关于iphone - 当有人给您打电话/发短信时暂停游戏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2114869/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com