gpt4 book ai didi

ios - NavigationView 在纵向模式下消失

转载 作者:行者123 更新时间:2023-11-28 11:25:55 26 4
gpt4 key购买 nike

为什么将我的设备旋转到纵向模式时,我的 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()
}
}

最佳答案

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

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"))
}
}

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

关于ios - NavigationView 在纵向模式下消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58124920/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com