Collapse a doubleColumn NavigationView detail in SwiftUI like with collapsed on UISplitViewController?

后端 未结 5 1458
渐次进展
渐次进展 2020-12-24 07:38

So when I make a list in SwiftUI, I get the master-detail split view for \"free\".

So for instance with this:

import SwiftUI

struct ContentView : Vi         


        
5条回答
  •  独厮守ぢ
    2020-12-24 08:06

    For current version (iOS 13.0-13.3.x), you can use my code. I use a UIViewUpdater to access the underlaying UIView and its UIViewController to adjust the bar item.

    I think the UIViewUpdater way to solve this problem is the most Swifty and robust way, and you can use it to access and modify other UIView, UIViewController related UIKit mechanism.

    ContentView.swift

    import SwiftUI
    
    struct ContentView : View {
        var people = ["Angela", "Juan", "Yeji"]
    
        var body: some View {
            NavigationView {
                List {
                    ForEach(people, id: \.self) { person in
                        NavigationLink(destination: DetailView()) { Text(person) }
                    }
                }
    
                InitialDetailView()
    
            }
        }
    }
    
    struct DetailView : View {
        var body: some View {
            Text("Hello!")
        }
    }
    
    struct InitialDetailView : View {
        var body: some View {
            NavigationView {
                Text("

提交回复
热议问题