如果主页按钮单击 iOS,则停止游戏应用程序 [英] Stop Game App if Home Button clicked iOS

查看:35
本文介绍了如果主页按钮单击 iOS,则停止游戏应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道 Apple 的规则是否有必要实现,当用户在游戏中时,如果他们点击主页按钮游戏暂停,当他们在游戏中点击返回时游戏取消暂停.

I don't know if by Apple's rules it's necessary to implement that when a user is in the middle of a game, if they click on home button the game pauses and when they click back in game, the game unpauses.

我是否必须点击情节提要上的某些内容才能显示主页按钮?我不知道.

Do I have to click something on storyboard for a home button to appear? I don't know.

由于故事板没有主页按钮,所以我如何编码,当用户单击主页按钮退出应用程序时,游戏会暂停.当他们再次返回时,游戏停止.

Since storyboards has no home button on it so how do I code that when user clicks home button to exit the app, the game pauses. When they return again, the game unpauses.

推荐答案

有两种实现方式:

1:使用NSNotificationCenter:

- (void)setupBackgroundNotification {
    // the same to applicationWillEnterForeground:
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(open)
                                                 name: UIApplicationWillEnterForegroundNotification
                                               object:nil];

    //// the same to applicationWillResignActive
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(close)
                                                 name: UIApplicationWillResignActiveNotification
                                               object:nil];
}


- (void)open {
    NSLog(@"the same to applicationWillEnterForeground");
}

- (void)close {
    NSLog(@"the same to applicationWillResignActive");
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:applicationWillEnterForeground object:Nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:applicationWillResignActive object:Nil];
}

2:使用UIApplicationDelegatedelegate方法

2: Use UIApplicationDelegatedelegate Method

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

这篇关于如果主页按钮单击 iOS,则停止游戏应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆