English 中文(简体)
SwiftUI SwiftUI 导航系统,具有共同的固定背景图像
原标题:SwiftUI NavigationStack with a shared, stationary background image
  • 时间:2024-05-20 23:37:46
  •  标签:
  • swiftui

能否让浏览器推动浏览器, 从导航系统中弹出, 而没有他们的背景图像也滑进/退出?

我试图实现的影响是整个堆栈后面的固定背景图像,而只有视图内容会滑进和滑出,而背景仍然可以保持和看得见。

This is the effect I d like to achieve, without dipping into UIKit if possible: https://web.archive.org/web/20191002173758/http://fabian-thies.tk/demo.gif (Gif taken from this SO question Push ViewController with transparent background)

问题回答

You could try this approach using background(..) and .scrollContentBackground(.hidden) in the parent view and ZStack in the child view, as shown in the example code:

struct ContentView: View {
    var body: some View {
        NavigationStack {
            List(["Apples", "Oranges", "Bananas"], id: .self) { item in
                NavigationLink(item, destination: NextView(fruit: item))
                    .listRowBackground(Color.clear)
            }
            .background(Color.green)
        }
        .scrollContentBackground(.hidden)
    }
}

struct NextView: View {
    let fruit: String
    
    var body: some View {
        ZStack {
            Color.green.ignoresSafeArea()
            Text(fruit)
        }
    }
}




相关问题
SwiftUI: How do I position a button x points above a sheet?

I am trying to recreate a Maps-style UI with a persistent bottom sheet and controls fixed above. Apple Maps UI with controls above ☝️ Example here, the "Look Around" binoculars button and ...

How to access own window within SwiftUI view?

The goal is to have easy access to hosting window at any level of SwiftUI view hierarchy. The purpose might be different - close the window, resign first responder, replace root view or ...

热门标签