如何使 mapkit 视图缩小一半并保持在顶部?
How to make the mapkit view half the size and stay on top?
我正在使用 Mapkit 来显示用户位置。我希望地图填满屏幕的一半并留在顶部。这是我试图让地图保持在顶部的代码。但是,我缩小了地图,但我无法让地图到达顶部。任何帮助将不胜感激。
ZStack(alignment: .top){
MapView().ignoresSafeArea(.all,edges: .all)
.environmentObject(mapData).frame(height: sizeOfMap, alignment: .topLeading)
}
正确的做法是使用 GeometryReader 在每个设备上保持相同的布局!
struct ContentView: View {
var body: some View {
GeometryReader { proxy in
VStack(spacing: 0.0) {
ZStack {
Color.blue
Text("MapView here!") // MapView()
}
.frame(height: proxy.size.height/2)
ZStack {
Color.red
Text("other View here!")
}
.frame(height: proxy.size.height/2)
}
}
.ignoresSafeArea()
}
}
我正在使用 Mapkit 来显示用户位置。我希望地图填满屏幕的一半并留在顶部。这是我试图让地图保持在顶部的代码。但是,我缩小了地图,但我无法让地图到达顶部。任何帮助将不胜感激。
ZStack(alignment: .top){
MapView().ignoresSafeArea(.all,edges: .all)
.environmentObject(mapData).frame(height: sizeOfMap, alignment: .topLeading)
}
正确的做法是使用 GeometryReader 在每个设备上保持相同的布局!
struct ContentView: View {
var body: some View {
GeometryReader { proxy in
VStack(spacing: 0.0) {
ZStack {
Color.blue
Text("MapView here!") // MapView()
}
.frame(height: proxy.size.height/2)
ZStack {
Color.red
Text("other View here!")
}
.frame(height: proxy.size.height/2)
}
}
.ignoresSafeArea()
}
}