从SceneDelegate访问viewController属性-Swift-以编程方式

时间:2020-10-02 13:37:08

标签: swift animation uiviewanimation foreground uiscenedelegate

我在相机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动画不起作用,关于什么可能导致此问题的建议?

0 个答案:

没有答案