xcode SwiftUI iPad应用程序在预览时全屏打开(如预期),但在模拟器中在侧边栏中打开最小化

ki0zmccv  于 2023-04-22  发布在  Swift
关注(0)|答案(1)|浏览(92)

预期行为(在预览中是这样工作的):https://i.stack.imgur.com/wLuQY.png
实际行为(模拟器中):https://imgur.com/a/mLIxPLJ
不幸的是,我没有一个物理设备来测试它在这个时候。
我已经更新了下面的代码,以包括“魔术”,因为也许我已经搞砸了一些东西在那里。LoginView和RegisterView是类似的(在zstack中的vstack),但用户名/密码的文本/安全字段。

import SwiftUI

import SwiftUI

struct ContentView: View {
    
    var body: some View {
        NavigationStack {
            ZStack{
                Color(K.BrandContent.onyx)
                    .ignoresSafeArea()
                VStack(spacing: 0.0) {
                    Spacer()
                    Image(K.BrandContent.logo)
                        .resizable()
                        .aspectRatio(contentMode: .fit)
                        .frame(width: 1000, alignment: .center)
                        .imageScale(.large)
                        .foregroundColor(.accentColor)
                    Text(K.BrandContent.name)
                        .font(.system(size: 70))
                        .fontWeight(.bold)
                        .foregroundColor(Color(K.BrandContent.red))
                    Spacer()
                    NavigationLink(destination: LoginView()) {
                        Text("Login")
                            .font(.system(size: 30, weight: .bold))
                            .foregroundColor(.black)
                    }
                    .frame(width: 300, height: 50)
                    .background(Color(K.BrandContent.white))
                    .padding(.vertical)
                    .containerShape(RoundedRectangle(cornerRadius: 25))
                    
                    NavigationLink(destination: RegisterView()) {
                        Text("Register")
                            .font(.system(size: 30, weight: .bold))
                            .foregroundColor(.black)
                    }
                    .frame(width: 300, height: 50)
                    .background(Color(K.BrandContent.white))
                    .padding(.vertical)
                    .containerShape(RoundedRectangle(cornerRadius: 25))
                    
                }
            }
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
        //.previewDevice(PreviewDevice(rawValue: K.Devices.ipad))
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
            .previewDevice(PreviewDevice(rawValue: K.Devices.ipad))
    }
}
vngu2lb8

vngu2lb81#

双列设置仅在以下情况下发生

NavigationView

或者

NavigationSplitView

如果您的预期导航设置为stack
您应该删除所有其他设置,并在应用程序的顶部只保留一个NavigationStack

相关问题