简体   繁体   English

SwiftUI 视图和 UIKit 视图的 z-index

[英]The z-index of SwiftUI View and UIKit View

The SwiftUI scroll view is hiding some area of a view presented from UIViewControllerRepresentable viewController. SwiftUI 滚动视图隐藏了从 UIViewControllerRepresentable viewController 呈现的视图的某些区域。

在此处输入图像描述

Part of the SwiftUI code, The GoogleMapsView is the UIViewControllerRepresentable viewController. SwiftUI 代码的一部分,GoogleMapsView 是 UIViewControllerRepresentable viewController。

struct ContentView: View {

var body: some View {
    ZStack(alignment: .top) {

        GoogleMapsView()

        VStack(alignment: .leading) {
            Text("Top Locations near you")

            ScrollView(.horizontal, showsIndicators: false) {
                HStack() {
                    ForEach(dataSource.topPlaces) { place in
                        PlaceCardView(placeImage: place.image, placeName: place.name, placeRating: place.rating, placeRatingTotal: place.ratingTotal, topPlace: place)
                    }
                }
                .padding(.horizontal, 10)
            }
            .background(Color.clear)
            .foregroundColor(.black)
            .frame(height: 200)
            .opacity(self.finishedFetching ? 1 : 0.1)
            .animation(.easeInOut(duration: 1.3))           
    }.edgesIgnoringSafeArea(.all)
}

The view I want to put on the top is from the GoogleMapView() which I put it on the "bottom" of the ZStack because I want that Scroll view to flow on the map.我想放在顶部的视图来自 GoogleMapView(),我将它放在 ZStack 的“底部”,因为我希望滚动视图在 map 上流动。 However the view show on the map when marker is tapped is cover up by the SwiftUI ScrollView然而,当点击标记时 map 上显示的视图被 SwiftUI ScrollView 掩盖

I tried to change their zIndex of the scrollView, zPosition of the pop up view or bringSubviewToFront etc. None of them work.我试图改变他们的滚动视图的zIndex,弹出视图的zPosition或bringSubviewToFront等。它们都不起作用。

You need to inject local state via binding into `` and change it there on popup shown/hidden.您需要通过绑定注入本地 state 到 `` 并在弹出窗口显示/隐藏时将其更改。

Here is some pseudo code这是一些伪代码

struct ContentView: View {

@State private var isPopup = false

var body: some View {
    ZStack(alignment: .top) {

        GoogleMapsView(isPopup: $isPopup)

        VStack(alignment: .leading) {
            Text("Top Locations near you")

            if !isPopup {
               ScrollView(.horizontal, showsIndicators: false) {
                  // other code
               }
               // other code
            }
    }.edgesIgnoringSafeArea(.all)
}

struct GoogleMapsView : UIViewControllerRepresentable {
   @Binding isPopup: Bool

   // other code

   // make self.isPopup = true before popup and false after

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM