将地图放置在另一个视图Swift UI上方

时间:2020-07-29 23:58:33

标签: swiftui

我希望地图始终位于底部滑块上方,只要底部滑块向上移动,地图就会随之移动并始终保持在其上方。

这是我的代码,顺便说一句,我今天开始行动迅速

 var body: some View {
ZStack(alignment: Alignment.top) {
        MapView()
     // From here I want the MapView which is google maps above the SlideOverCard
        SlideOverCard {
            VStack {
                Text("Whatever")
                    .font(.headline)
                
            }.frame(width: 1000)
        }
    }
    .edgesIgnoringSafeArea(.vertical)
}

1 个答案:

答案 0 :(得分:1)

您可以在.zIndex中给ZStack或更改视图顺序(最新的将是最高的)

A)

ZStack(alignment: Alignment.top) {
        MapView().zIndex(1)         // by default all views has 0
        SlideOverCard {

B)

ZStack(alignment: Alignment.top) {
        SlideOverCard {
            // ... other code here
        }
        MapView()      // will be above
}