swift - 从 SceneDelegate 访问 viewController 属性 - Swift - 以编程方式
问题描述
我在相机 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 动画不起作用,有什么建议可以导致这个问题吗?
解决方案
推荐阅读
- cassandra - 访问远程 cassandra 数据库
- javascript - 4 FOSJSRouting 回调=fos.Router.setData & Route 仅在生产中找不到
- video-processing - 更改 HM 参考软件以显示有关比特流的一些信息
- caching - 图像压缩的最佳做法是什么
- speech-recognition - 语音到文本的大型音频文件 [Microsoft Speech API]
- azure-active-directory - AzureAD SAML 响应
- scala - 使用 PrivateMethodTester 测试 curried 方法
- android - OpenStreetMap Android MapView 在缩放后加载 Tiles
- python - Numpy 将 3d 矩阵乘以 2d 矩阵
- c++ - 多线程应用程序的壁时间分析