SwiftUI iPad app opening full screen (as expected) on preview, but in simulator opens minimised in the sidebar

huangapple go评论65阅读模式
英文:

SwiftUI iPad app opening full screen (as expected) on preview, but in simulator opens minimised in the sidebar

问题

预期行为(在预览中以这种方式工作):https://i.stack.imgur.com/wLuQY.png

实际行为(在模拟器中):
https://i.stack.imgur.com/ZKaAR.jpg

很遗憾,我目前没有物理设备进行测试。

我已更新下面的代码,包括“magic”,因为我可能在其中搞砸了。LoginView 和 RegisterView 类似(vstack 在 zstack 中),但具有用于用户名/密码的文本/安全字段。

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))
    }
}
英文:

Expected behaviour (and it works this way in the preview): https://i.stack.imgur.com/wLuQY.png

Actual behaviour (in the simulator):
https://i.stack.imgur.com/ZKaAR.jpg

Unfortunately, I do not have a physical device to test it out on at this time.

I've updated the code below to include the 'magic' as maybe I've screwed something up in there. The LoginView and RegisterView are similar (vstack in a zstack) but with text/secure fields for username/password.

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

答案1

得分: 1

双列设置仅在导航视图(NavigationView)或导航分割视图(NavigationSplitView)中发生。

如果你的预期导航设置是堆栈(stack),

应删除所有其他设置,仅保留应用程序顶部的单个NavigationStack

英文:

The Double Column setup only happens with

NavigationView

Or

NavigationSplitView

If your intended navigation setup is stack.

You should remove all other setups and leave only a single NavigationStack at the very top of the app.

huangapple
  • 本文由 发表于 2023年4月20日 01:55:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/76057519.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定