[英]How to get notified when application goes background?
在進入后台之前,我需要保護我的應用程序免於截屏。 我在applicationDidEnterBackground:
添加了一個黑色視圖。 但是,當我在iOS7模擬器中檢查后台應用程序時,它沒有顯示黑色圖像,而是顯示了應用程序本身,如圖所示。 我該如何解決? 如果我在應用程序進入后台之前收到通知,則可能會解決此問題。 任何幫助將不勝感激。
您將在AppDelegate的applicationDidEnterBackground
獲得回調
在整個應用程序中實現所需功能的最好方法是使應用程序導航到全黑的UIViewController。 這樣一來,當您長按主頁按鈕並查看后台應用程序時,您將看不到任何內容。
這兩個功能可以解決問題:
- (void) applicationDidEnterBackground:(UIApplication *)application
{
//navigate to the black view controller
BlackViewController *controller = [[BlackViewController alloc] init];
[yourNavigationController pushViewController:viewController animated:yourAnimationSettings];
[controller release];
}
- (void) applicationWillEnterForeground:(UIApplication *)application
{
//pop the black view controller so the user won't be bothered with it
if(/*Check if your BlackViewController is the top of your navigationController stack*/)
{
[yourNavigationController popViewControllerAnimated:yourAnimationSettings];
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.