Prevent iOS from taking screen capture of app before going into background

后端 未结 10 2683
Happy的楠姐
Happy的楠姐 2020-11-29 22:35

You all might know that iOS takes a screen shot of your application before throwing it into the background. This is usually for a better User experience like quick animation

10条回答
  •  悲&欢浪女
    2020-11-29 23:19

    swift 4.0 version.

    for use custom icon

    first add this line at top of AppDelegate

    var imageView: UIImageView?
    

    and add this:

    func applicationDidEnterBackground(_ application: UIApplication) {
        imageView = UIImageView(frame: window!.frame)
        imageView?.image = UIImage(named: "AppIcon")
        window?.addSubview(imageView!)
    }
    
    func applicationWillEnterForeground(_ application: UIApplication) {
        if imageView != nil {
            imageView?.removeFromSuperview()
            imageView = nil
        }
    }
    

    background with black color

    func applicationDidEnterBackground(_ application: UIApplication) {
        let blankViewController = UIViewController()
        blankViewController.view.backgroundColor = UIColor.black
        window?.rootViewController?.present(blankViewController, animated: false)
    }
    
    func applicationWillEnterForeground(_ application: UIApplication) {
        window?.rootViewController?.dismiss(animated: false)
    }
    

提交回复
热议问题