Just in case someone is still working through this issue, or one close to it.
My issue was where both Views where SwiftUI Views (one an Image and the other a user interactive Form full of Sections and widgets). I wanted the image to set up a look and feel for the form being filled in.
The answer is to go around SwiftUI by adjusting your thinking and make the Image fully opaque and the Form see through at about 80% - or to taste. Then mark the Image non-interactive (.allowsHitTesting(false)) and the Form interactive (.allowsHitTesting(true)).
My implementation used View Modifiers:
// Original Form
Form { (various Widgets) }
.texturedBackground(named: "MapleWoodGrain")
extension View {
func texturedBackground(named name: String) -> some View
{
return self.modifier(PatternBackground(imageName: name))
}
}
public struct PatternBackground: ViewModifier {
var imageName : String
public func body(content: Content) -> some View {
ZStack {
Image(imageName)
.resizable(resizingMode: .tile)
.allowsHitTesting(false)
content
.opacity(0.8)
.allowsHitTesting(true)
}
}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: