ios - 如何在 SwiftUI 中模糊视图的一部分
问题描述
我想在 SwiftUI 中模糊相机视图的一部分。像一个模糊的框架。
我的想法是为相机视图创建一个修改器,如下面的代码中的修改器。但是,当我应用修改器时,模糊的内容content.blur(radius: 7)
也会被剪裁!
你能帮我理解为什么这不起作用吗?
struct MaskedCameraBlur: ViewModifier {
// This is just the store in which the cropArea is saved
@EnvironmentObject var dataStore : MyDataStore
func body(content: Content) -> some View {
ZStack {
content.blur(radius: 7) // this should not be clipped
content.clipShape(Rectangle().path(in: dataStore.cropArea))
}
}
}
extension View {
func maskedCameraBlur() -> some View {
self.modifier(MaskedCameraBlur())
}
}
编辑:
我想补充一点,我能够通过使用UIVisualEffectView
. 在我的 github 中查看解决方案
但是,我仍然希望仅使用纯 SwiftUI 来实现相同的目标,如果您能指出正确的方向,我将不胜感激。谢谢你。
解决方案
推荐阅读
- r - Tidyverse 版本的嵌套 for 循环
- c - c中的“if”块如何工作,如果在“if”块中赋值?例如 if(i=0){ //some code } 将流到 if 块中
- c# - 使用安装程序添加自定义注册表项
- python - 如何在python中比较两个列表的每个元素
- swift - 通过字符串进行类型转换
- javascript - 将参数传递给没有 react-router-dom 中的 url 的路由
- android - 如何设置图像宽度以占用 ConstraintLayout 中的一半空间
- android - 尝试通过 Android 代码设置权重
- laravel - 仅在非 www 上强制 HTTPS
- python - Python - 如何从列表中提取文本