【发布时间】:2022-12-01 15:13:37
【问题描述】:
I am displaying HStack on top of MapView using ZStack. The problem that i am facing is user touches can still respond to MapView from the Spacing between Hstack. How can i prevent this? A trick that i can use is set invisible background color.
.background(Color.black.opacity(0.0001))
import SwiftUI
import MapKit
struct ConfusedView: View {
@State private var region = MKCoordinateRegion(
center: CLLocationCoordinate2D(
latitude: 51.23,
longitude: -0.1275),
span: MKCoordinateSpan(
latitudeDelta: 0.5,
longitudeDelta: 0.5)
)
var body: some View {
ZStack {
Map(coordinateRegion: $region)
HStack(spacing: 50) {
Rectangle()
.fill(.red)
.frame(width: 100)
Rectangle()
.fill(.red)
.frame(width: 100)
Rectangle()
.fill(.red)
.frame(width: 100)
}
//.background(Color.black.opacity(0.0001))
.border(Color.green, width: 10)
.frame(height: 300)
}
}
}
struct ConfusedView_Previews: PreviewProvider {
static var previews: some View {
ConfusedView()
}
}
I also tried using contentShape but didnot work. Whats the best way to handle this case?
【问题讨论】: