Preventing snapshot view of your app when coming back from multi-tasking

为君一笑 提交于 2019-11-30 08:55:44

I solved this. Here is the solution:

- (void)applicationDidEnterBackground:(UIApplication *)application{
    if (appHasPasscodeOn){
        UIImageView *splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, 480)];
        splashView.image = [UIImage imageNamed:@"Default.png"];
        [window addSubview:splashView];
        [splashView release];
    }
}

Default.png is a screenshot of my app with a blank screen (for me it's just a blank listview). The code above puts that in front of my real view right before the app goes into the background. So, when you come back to the app that is all you see. Voila.

The marked answer works perfectly for me except that when the app becomes active again the splashView stays on screen. I just made it a property and added [splashView removeFromSuperview] into my applicationWillEnterForeground to fix it. In case anyone else gets similar behavior.

Marijn

Here is the above solution in Swift 3.0:

lazy var splashImageView: UIImageView = {
    let splashImageView = UIImageView(frame: UIScreen.main.bounds)
    splashImageView.image = UIImage(named: "splash-view")
    return splashImageView
}()

func applicationDidEnterBackground(_ application: UIApplication) {
    window?.addSubview(splashImageView)
}

func applicationWillEnterForeground(_ application: UIApplication) {
   splashImageView.removeFromSuperview()
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!