accessing viewController property from SceneDelegate - Swift - Programmatically

88 views Asked by At

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?

0

There are 0 answers