     
     func tabBarController(_ tabBarController: UITabBarController,
                           didSelect viewController: UIViewController){
+        
         if tabBarController.viewControllers?.index(of: viewController) == 3 {
-            if let backImage = backImage {
+            if previousIndex == 4 {
+                viewController.view.backgroundColor = UIColor.white
+            }
+            else if previousIndex != 3 {
                 viewController.view.backgroundColor = UIColor(patternImage: backImage)
-            }
-            else {
-                viewController.view.backgroundColor = UIColor.white
             }
         }
 

    
 
    func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
        if tabBarController.selectedIndex == 4 {
            backImage = nil
        }
        else if tabBarController.viewControllers?.index(of: viewController) == 3 {
            backImage = snapView(targetView: tabBarController.view)
        }
        

        UIGraphicsEndImageContext()
        return snapdImage!
    }
    
    func blurImage(targetImage: UIImage) -> UIImage {
        let ciImage = CIImage(image: targetImage)
        let filter = CIFilter(name: "CIGaussianBlur")!
        //filter.setDefaults()
        filter.setValue(ciImage, forKey: kCIInputImageKey)
        let resultImage = filter.value(forKey: kCIOutputImageKey) as! CIImage
        let context = CIContext()
        let cgImage = context.createCGImage(resultImage, from: resultImage.extent)!
        
        let blurredImage = UIImage(cgImage:cgImage)
        //let blurredImage = UIImage(ciImage: resultImage)
        return blurredImage
        
        

    }
        
    
    
//
//   
