There are two views (Slider and Button) under a view (Rectangle):
struct ContentView: View {
//@State var val = false
@State var floatVal = 0.0
var body: some View {
ZStack {
VStack {
Text("Control penetration")
.font(.title)
//Slider can't slide
Slider(value: $floatVal, in: 0...100)
//Toggle can't toggle too
//Toggle(isOn: $val){EmptyView()}
//only button can tap
Button(action: {
print("Tapped!")
}){
Text("Can you tap me???")
}
}
.padding()
Rectangle()
.fill(Color.green.opacity(0.2))
.allowsHitTesting(false)
}
}
}
I use allowsHitTesting() to make the click penetrate to the bottom.
But only the Button can respond to click, the Slider can not slide!
What’s wrong with it? How can I make the Slider respond slide too? thanks a lot!