In SwiftUI, I'm trying to make a map, and when the user clicks on one of the stops, the info sheet will pop up.
I was going use the map in a ZStack, but how do I place the buttons on top of the stops; how do I define the position of the button so this works in landscape or portrait?
struct ContentView: View {
var body: some View {
GeometryReader { geometry in
VStack{
ZStack {
Image("background")
.resizable()
.aspectRatio(contentMode: .fit)
Button(action: {}) {
Text("Button")
}.position(x: 200, y: 150)
}.frame(width: geometry.size.width, height: geometry.size.height/4)
myMasterDetailView()
}
}
}
}
struct myMasterDetailView: View {
var body: some View {
GeometryReader { geometry in
HStack{
myMasterView()
.frame(width: geometry.size.width / 2, height: geometry.size.height)
.background(Color.yellow)
VStack {
myDetailView()
.frame(width: geometry.size.width / 2, height: geometry.size.height*2/3)
.background(Color.orange)
Text("Comment area")
.frame(width: geometry.size.width / 2, height: geometry.size.height/3)
}
}
}
}
}
struct myMasterView: View {
var body: some View {
Text("Master View")
}
}
struct myDetailView: View {
var body: some View {
Text("Detail View")
}
}
Link for background file: background.png
ZStackyou can draw stuff on top of each other :) - krjw