NavigationView在纵向模式下消失

时间:2019-09-26 21:20:57

标签: ios swift xcode swiftui

将设备旋转到纵向模式后,为什么我的NavigationView消失了。我已经为我的应用启用了所有方向。

enter image description here

enter image description here

import SwiftUI

struct Stocks: Identifiable{
    var id  = UUID()
    var name = String()
}

struct ContentView: View {

    let stocks: [Stocks] = [
        Stocks(name: "Agricultural Bank of China"),
        Stocks(name: "China Communications Construction"),
        Stocks(name: "China Communications Construction Company Limited"),
        Stocks(name: "China Merchants Shekou Industrial Zone Holdings"),
        Stocks(name: "China Railway Construction Corporation Limited"),
        Stocks(name: "China State Construction Engineering Corporation "),
        Stocks(name: "Daqin Railway Company Limited"),
        Stocks(name: "Guotai Junan Securities"),
        Stocks(name: "Huaneng Power International"),
        Stocks(name: "Industrial and Commercial Bank of China"),
        Stocks(name: "Jiangsu Yanghe Brewery"),
        Stocks(name: "Kweichow Moutai"),
        Stocks(name: "Ping An Bank"),
        Stocks(name: "Shanghai International Port Group"),
        Stocks(name: "Shanghai Pudong Development Bank"),
        Stocks(name: "Wuliangye Yibin Company Limited")]

    var body: some View {
        NavigationView {
            List(stocks) {stock in
                    VStack(alignment: .leading){
                        Text(stock.name).font(.title)
                    }
            }
            .navigationBarTitle(Text("FTSE China A50 Index"))
        }
    }
}
struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

1 个答案:

答案 0 :(得分:3)

将iPad旋转到纵向模式时,它将隐藏左窗格,可以通过从左边缘滑动来再次显示它。我还没有找到防止这种情况自动隐藏的方法。如果稍微修改一下代码,您会清楚地看到发生了什么:

var body: some View {
    NavigationView {
        List(stocks) {stock in
            VStack(alignment: .leading){
                NavigationLink(stock.name, destination: Text(stock.name)).font(.title)
            }
        }
        .navigationBarTitle(Text("FTSE China A50 Index"))
    }
}

现在,如果单击一行,您将在右侧的详细信息窗格中看到它,并且会注意到,如果旋转到纵向,则会显示该行。