在SwiftUI中,在横向模式下导航中断

在SwiftUI中,在横向模式下导航中断,swiftui,Swiftui,大家下午好 我的应用程序有问题,我试图使它在两种情况下都看起来不错,所以当我改变方向时,我的应用程序返回主屏幕,它不会停留在第二个屏幕上,有人能解决这个问题吗 我不知道我的视图是否中断或无法覆盖我已确定的空间,我将代码留在下面 import SwiftUI struct LoginView: View { @Environment(\.presentationMode) var presentationMode: Binding<PresentationMode> init()

大家下午好

我的应用程序有问题,我试图使它在两种情况下都看起来不错,所以当我改变方向时,我的应用程序返回主屏幕,它不会停留在第二个屏幕上,有人能解决这个问题吗

我不知道我的视图是否中断或无法覆盖我已确定的空间,我将代码留在下面

import SwiftUI

struct LoginView: View {

@Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>

init() {
         UINavigationBar.appearance().setBackgroundImage(UIImage(), for: UIBarMetrics.default)
         UINavigationBar.appearance().shadowImage = UIImage()
         UINavigationBar.appearance().isTranslucent = true
         UINavigationBar.appearance().tintColor = .clear
         UINavigationBar.appearance().backgroundColor = .clear
    }


var backButton : some View {
    Button(action: {
       self.presentationMode.wrappedValue.dismiss()
       }) {
           HStack {
           Image("Backarrow")
               .aspectRatio(contentMode: .fit)
               .foregroundColor(.white)
               Text(" Back")
                .foregroundColor(.yellow)
           }
       }
   }

var topImage:some View{
        Image("header2")
            .resizable()
            .overlay( ImageOverlay() , alignment: .center)
            .background(Color.black)
}

var usernameTextField:some View{
    
        HStack{
            TextField("", text: $LoginViewM.username)
                .placeholder(Text("Numero de telefono,email o usuario").padding().foregroundColor(.white), show: LoginViewM.password.isEmpty)
                .background(Color.black)
            Image("menuCloseSmall")
                .padding(.init(top: 0, leading: 0, bottom: 0, trailing: 14))
        }
        .lineLimit(1)
        .foregroundColor(.white)
         .minimumScaleFactor(0.5)
        .font(.custom("Montserrat-Regular", fixedSize: 16.4))
        .overlay(RoundedRectangle(cornerRadius: 4).stroke(Color.gray, lineWidth: 3))
        .clipShape(RoundedRectangle(cornerRadius: 4))
   }

var errorUsernameLabel:some View{
    VStack{
        Text("    Hey you, no user found. Make sure you’ve provided the ")
            .lineLimit(1)
           Text("correct information.")
    }
    .multilineTextAlignment(.leading)
    .foregroundColor(.redBlueParrot)
    .minimumScaleFactor(0.5)
    .font(.custom("Montserrat-Regular", size: 12.1))
}

var passwordTextField:some View{
    HStack{
        TextField("Contraseña", text: $LoginViewM.password)
            .font(.custom("Montserrat-Regular", fixedSize: 16.4))
            .padding(.bottom)
            .foregroundColor(.white)
            .placeholder(Text("Contraseña").padding().foregroundColor(.white), show: LoginViewM.username.isEmpty)
            .lineLimit(1)
            .minimumScaleFactor(0.5)
            .background(Color.black)
        Image("editShow")
            .padding(.init(top: 0, leading: 0, bottom: 0, trailing: 14))
    }
    .overlay(RoundedRectangle(cornerRadius: 4).stroke(Color.gray, lineWidth: 3))
    .clipShape(RoundedRectangle(cornerRadius: 4))   
  }

var errorPasswordLabel:some View{
    VStack{
        Text("      Incorrect password for \(LoginViewM.password). Please try again.")
    }
        .lineLimit(1)
        .minimumScaleFactor(0.5)
        .foregroundColor(.redBlueParrot)
        .font(.custom("Montserrat-Regular", size: 12.1))
}
var buttonLogin:some View{
    
    NavigationLink(
        destination: Text("Hola"),
        label: {
            Text("Iniciar sesion")
        })            .font(.custom("Montserrat-Medium", size: 16))
        .foregroundColor(Color.ligthGray)
        .frame(minWidth: 0, idealWidth: 174, maxWidth: 174, minHeight: 0, idealHeight: 48, maxHeight: 48, alignment: .center)
        .overlay(RoundedRectangle(cornerRadius: 18)
        .stroke(Color.gray, lineWidth: 1.5))
        
    
}

var textInBottom:some View{
    
    HStack(spacing:5){
        Text("Olvidaste tu")
            .foregroundColor(.white)
            .font(.custom("Montserrat-Regular", size: 16))
        Button("contraseña"){
            
        }
        .foregroundColor(.yellow)
        .font(.custom("Montserrat-Regular", size: 16))
        Text("o")
            .foregroundColor(.white)
            .font(.custom("Montserrat-Regular", size: 16))
        Button("usuario"){
            
            
        }
        .foregroundColor(.yellow)
        .font(.custom("Montserrat-Regular", size: 16))
    }
}


@ObservedObject var LoginViewM = LoginViewModel()

var body: some View {
    
    GeometryReader{ geometry in
        NavigationView{
            VStack(spacing:2){
                topImage
                    .frame(width: geometry.size.width, height: geometry.size.height * 0.39)
                
                VStack(spacing:17){
                    usernameTextField
                        .frame(width: geometry.size.width*0.90, height: geometry.size.height*0.05)
                    errorUsernameLabel
                        .frame(width: geometry.size.width*0.90,height: geometry.size.height*0.06, alignment: .center)
                    
                    passwordTextField
                        .frame(width: geometry.size.width*0.90, height: geometry.size.height*0.05)
                
                    errorPasswordLabel
                        .frame(height: geometry.size.height*0.06, alignment: .center)
                    
                }.frame( height: geometry.size.height * 0.40)
               
                VStack{
                    buttonLogin
                }.frame(height: geometry.size.height * 0.10, alignment: .center)
                
                Spacer()
                textInBottom
                        .frame(height: geometry.size.height * 0.05, alignment: .center)
                Spacer()
                        
            }

            .ignoresSafeArea(.all)
            .background(Color.black)
        }
         .navigationBarItems(leading: backButton)
        .navigationBarBackButtonHidden(true)
       .background(Color.black)
    .navigationViewStyle(StackNavigationViewStyle())
    }
       
  }

 }
    
struct LoginView_Previews: PreviewProvider {
static var previews: some View {
    LoginView()
  }
}
导入快捷界面
结构逻辑视图:视图{
@环境(\.presentationMode)变量presentationMode:绑定
init(){
UINavigationBar.appearance().setBackgroundImage(UIImage(),for:UIBarMetrics.default)
UINavigationBar.appearance().shadowImage=UIImage()
UINavigationBar.appearance().isTranslucent=true
UINavigationBar.appearance().tintColor=.clear
UINavigationBar.appearance().backgroundColor=.clear
}
var backButton:一些视图{
按钮(操作:{
self.presentationMode.wrappedValue.discouse()文件
}) {
HStack{
图像(“反箭头”)
.aspectRatio(内容模式:.fit)
.foregroundColor(.白色)
文本(“背面”)
.foregroundColor(.黄色)
}
}
}
var topImage:一些视图{
图像(“标题2”)
.可调整大小()
.overlay(ImageOverlay(),对齐:。居中)
.背景(颜色.黑色)
}
var usernameTextField:一些视图{
HStack{
TextField(“,text:$LoginViewM.username)
.placeholder(文本(“电话号码、电子邮件地址”).padding().foregroundColor(.white),show:LoginViewM.password.isEmpty)
.背景(颜色.黑色)
图像(“小菜单”)
.padding(.init(顶部:0,前导:0,底部:0,尾随:14))
}
.lineLimit(1)
.foregroundColor(.白色)
.最小比例因子(0.5)
.font(.custom(“蒙特塞拉特常规”,固定大小:16.4))
.overlay(圆角矩形(拐角半径:4).笔划(颜色.灰色,线宽:3))
.clipShape(圆角半径:4))
}
var errorUsernameLabel:一些视图{
VStack{
文本(“嘿,你,找不到用户。请确保你已提供了”
.lineLimit(1)
文本(“正确信息”)
}
.multilitextalignment(.leading)
.foregroundColor(.redBlueParrot)
.最小比例因子(0.5)
.font(.custom(“蒙特塞拉特普通”,大小:12.1))
}
var passwordTextField:一些视图{
HStack{
TextField(“Contraseña”,text:$LoginViewM.password)
.font(.custom(“蒙特塞拉特常规”,固定大小:16.4))
.padding(.bottom)
.foregroundColor(.白色)
.placeholder(Text(“Contraseña”).padding().foregroundColor(.white),show:LoginViewM.username.isEmpty)
.lineLimit(1)
.最小比例因子(0.5)
.背景(颜色.黑色)
图像(“编辑秀”)
.padding(.init(顶部:0,前导:0,底部:0,尾随:14))
}
.overlay(圆角矩形(拐角半径:4).笔划(颜色.灰色,线宽:3))
.clipShape(圆角半径:4))
}
var errorPasswordLabel:一些视图{
VStack{
文本(“不正确的\(LoginViewM.password)密码)。请重试。”)
}
.lineLimit(1)
.最小比例因子(0.5)
.foregroundColor(.redBlueParrot)
.font(.custom(“蒙特塞拉特普通”,大小:12.1))
}
var buttonLogin:一些视图{
导航链接(
目的地:文本(“Hola”),
标签:{
文本(“Iniciar sesion”)
}).font(.custom(“蒙特塞拉特中等”,大小:16))
.前底色(浅灰色)
.frame(最小宽度:0,理想宽度:174,最大宽度:174,最小高度:0,理想高度:48,最大高度:48,对齐方式:。中心)
.叠加(圆角半径:18)
.笔划(颜色.灰色,线宽:1.5))
}
var textInBottom:一些视图{
HStack(间距:5){
文本(“Olvidaste tu”)
.foregroundColor(.白色)
.font(.custom(“蒙特塞拉特普通”,大小:16))
按钮(“反转键”){
}
.foregroundColor(.黄色)
.font(.custom(“蒙特塞拉特普通”,大小:16))
文本(“o”)
.foregroundColor(.白色)
.font(.custom(“蒙特塞拉特普通”,大小:16))
按钮(“usuario”){
}
.foregroundColor(.黄色)
.font(.custom(“蒙特塞拉特普通”,大小:16))
}
}
@ObservedObject变量LoginViewM=LoginViewModel()
var body:一些观点{
GeometryReader{中的几何体
导航视图{
VStack(间距:2){
头像
.frame(宽度:geometry.size.width,高度:geometry.size.height*0.39)
VStack(间距:17){
usernameTextField
.框架(宽度:几何。尺寸。宽度*0.90,高度:几何。尺寸。高度*0.05)
errorUsernameLabel
.frame(宽度:几何体。大小。宽度*0.90,高度:几何体。大小。高度*0.06,对齐:。中心)
密码文本字段
.框架(宽度:几何。尺寸。宽度*0.90,高度:几何。尺寸。高度*0.05)
错误密码标签
.frame(高度:几何体。大小。高度*0.06,对齐:。中心)
}.框架(高度:几何尺寸高度*0.40)
VStack{
巴顿洛金
}.frame(高度:geometry.size.height*0.10,对齐:。中心)
垫片()
文本底部
.frame(高度:geometry.size.height*0.05,对齐:。中心)
垫片()
}
.ignoresSafeArea(.all)
.背景(C)