0

我在相机 ViewController 中有一个 blurEffect,每当我从一个 viewController 传递到另一个时,我都会使用它来模糊 cameraView。

我这样做,为它的 alpha 值设置动画。

这些是模糊效果变量:

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

我希望当应用程序进入后台或前台时,我可以访问属性并更改 alpha 值。

这就是我在 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
    
}

我可以正确访问 cameraViewController 但 blurView.alpha 动画不起作用,有什么建议可以导致这个问题吗?

4

0 回答 0