2017-01-14 90 views
0

當我打開我的應用程序時,我的界面出現了一些問題,轉到背景並最終返回到前景。所以我想強制我的應用程序始終啓動應用程序,當我從背景中回來時。 我看到Clash Royale遊戲就是這樣工作的。 我正在用swift開發3從後臺回來後強制啓動應用程序。 Swift 3

+0

你有沒有試過http://stackoverflow.com/a/3098252/1072229? –

回答

1

我不確切地知道你的主頁看起來像從背景返回後想要加載的內容,但是你應該能夠使用AppDelegate中的函數來能夠設置值並在從背景狀態返回時根據需要加載場景或視圖,或者在應用程序關閉時設置所需的視圖。

這是一個已經內置到AppDelegate中的函數列表。

func applicationWillResignActive(_ application: UIApplication) { 
    // 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 invalidate graphics rendering callbacks. Games should use this method to pause the game. 
} 

func applicationDidEnterBackground(_ application: UIApplication) { 
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 
} 

func applicationWillEnterForeground(_ application: UIApplication) { 
    // 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. 
} 

func applicationDidBecomeActive(_ application: UIApplication) { 
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 
} 

func applicationWillTerminate(_ application: UIApplication) { 
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 
} 
+0

由於某種原因,applicationWillResignActive沒有格式化爲代碼。對於那個很抱歉。 – crpDave

+0

感謝您修復@LeoDabus。由於某種原因,它不接受我的編輯。 – crpDave

相關問題