-1

Apple のルールにより、ユーザーがゲームの途中でホーム ボタンをクリックするとゲームが一時停止し、ゲームに戻るとゲームが一時停止するように実装する必要があるかどうかはわかりません。

ホーム ボタンを表示するには、ストーリーボード上の何かをクリックする必要がありますか? 知らない。

ストーリーボードにはホーム ボタンがないため、ユーザーがホーム ボタンをクリックしてアプリを終了すると、ゲームが一時停止するようにコーディングするにはどうすればよいですか。彼らが再び戻ってくると、ゲームは一時停止を解除します。

4

4 に答える 4

0

CMDiOSシミュレーターでは、 ++ショートカットで「ホームボタンを押す」ことができますSHIFTH

UIApplicationDelegate 実装で次のメソッドをオーバーライドできます。

applicationWillResignActive: (フォアグラウンド状態を終了するときに呼び出されます。)
applicationWillEnterForeground: (バックグラウンド状態から移行するときに呼び出されます。)

または、NSNotificationCenter と同等の通知を使用できます。

UIApplicationWillEnterForegroundNotification
UIApplicationWillResignActiveNotification

iOS がアプリをバックグラウンドに置くと、アプリは実行されなくなるという点で、基本的に一時停止されます (音楽プレーヤー、GPS コンシューマーなどは例外です)。しかし、レンダリング ループは何もしていません。ただし、この状態ではアプリが強制終了される可能性があるため、アプリの状態の一貫性を維持するために簿記を行う必要があります。アプリを一時停止したり、ユーザーの進行状況を保存したりしてから、再開/再起動して、戻ってきたときにその情報を読み込んでも問題ありません。

于 2015-05-27T16:23:28.340 に答える
0

それを実装するには、次の 2 つの方法があります。

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:UIApplicationDelegateデリゲート メソッドを使用する

- (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.
}
于 2015-05-27T16:23:53.207 に答える
0

単純なゲームを作成している場合、一時停止するために何も実装する必要はありません。メモリ管理メカニズムがそれを処理します。

ただし、インターネット接続などの機能が必要なゲームを作成している場合は、タスクをどう処理するかを処理する必要があります。たとえば、Apple のUIApplicationDelegateリファレンス ページを確認してください。「状態遷移の管理」セクションを参照して、理解を深めてください。

于 2015-05-27T16:15:45.263 に答える