0

I have a blurEffect in a camera ViewController that I use to blur the cameraView whenever I pass from a viewController to another.

I do that, animating the alpha value of it.

These are the blur effect variables:

var blur = UIBlurEffect(style: .dark)
var blurView = UIVisualEffectView()

I want that when the app enters in background or in foreground I can access the properties and change the alpha value.

This is what I did in SceneDelegate:

func sceneWillEnterForeground(_ scene: UIScene) {

    guard let cameraViewController = tabbarviewcontroller.viewControllers[1].viewControllers.first as? CameraViewController else{
        print("there is an error in retrieving the cameraController")
        return
    }
    
    UIView.animate(withDuration: 0.25, delay: 0.2, options: [.curveEaseOut,. allowUserInteraction], animations: {
        cameraViewController.blurView.alpha = 0
    })
}

func sceneDidEnterBackground(_ scene: UIScene) {
    
    guard let cameraViewController = tabbarviewcontroller.viewControllers[1].viewControllers.first as? CameraViewController else{
               print("there is an error in retrieving the cameraController")
               return
           }

    cameraViewController.blurView.alpha = 1
    
}

I can access the cameraViewController correctly but the blurView.alpha animation doesn't work, any suggestions on what could cause this problem?

StackGU
  • 868
  • 9
  • 22
  • 1
    Just a note (This doesn't solve the problem but you should be aware of it): "When using the UIVisualEffectView class, avoid alpha values that are less than 1. [...]" Found here: https://developer.apple.com/documentation/uikit/uivisualeffectview – Teetz Oct 02 '20 at 14:13
  • thanks I'll keep in mind – StackGU Oct 02 '20 at 14:17

0 Answers0