【问题标题】:Keyboard not overlaying the view in SwiftUI键盘不覆盖 SwiftUI 中的视图
【发布时间】:2021-06-24 15:56:36
【问题描述】:

所以我希望我的键盘覆盖视图,以便视图保持不变而不向上。我做了几个变体,比如将它添加到我的登录信息中,或者添加到它的导航视图中。它根本不起作用

这是我的代码

struct LoginView: View {
    @StateObject var userData = UserData()
    var body: some View {
        NavigationView {
            ZStack(alignment:.top) {
                Color.pink.ignoresSafeArea(edges: .top)
                VStack {
                    Image(systemName: "graduationcap.fill")
                        .resizable()
                        .scaledToFit()
                        .frame(width: /*@START_MENU_TOKEN@*/100/*@END_MENU_TOKEN@*/, height: /*@START_MENU_TOKEN@*/100/*@END_MENU_TOKEN@*/, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
                        .foregroundColor(.white)
                        .padding(.top,30)
                    Text("Study +")
                        .font(.title)
                        .fontWeight(.medium)
                        .foregroundColor(.white)
                    Spacer()
                    //Mark : The login Thinggy
                    LoginStuffs()
                }
            }
            .edgesIgnoringSafeArea(.bottom)
            .navigationTitle("Login")
            .navigationBarHidden(true)
        }
    }
}

登录资料

struct LoginStuffs: View {
    @State var username:String = ""
    @State var password:String = ""
    @State var isShow:Bool = false
    var body: some View {
       Vstack{
Textfield()
Securefield()
Securefield()
        }
        .padding()
        .frame(width:UIScreen.width,height:UIScreen.height/1.5)
        .background(Color.white)
        .cornerRadius(15, corners: [.topLeft, .topRight])
        //.ignoresSafeArea(edges: /*@START_MENU_TOKEN@*/.bottom/*@END_MENU_TOKEN@*/)
    }
}

似乎我的代码中存在我不知道的问题(可能是由于没有正确学习)。请帮忙,谢谢您的关注

【问题讨论】:

  • 我已经尝试将.ignoresSafeArea(.keyboard) 添加到视图中,但没有成功
  • 添加LoginStuffs()
  • 我做了,我尝试了变化,没有工作
  • 我的意思是添加 LoginStuffs().. 的代码 :)
  • 好的。给你

标签: swiftui swiftui-navigationview


【解决方案1】:

在您的 NavigationView 上使用

.edgesIgnoringSafeArea(.bottom))

【讨论】:

  • 如果 NavigationView 嵌套在另一个视图中添加到那个视图中,您必须将它添加到顶层视图中
  • 我确实把它放在了顶层(我认为)
  • 我没有,您正在使用其他视图中的 LoginView,如果不起作用,请尝试将其添加到 LoginView 将其添加到包含 LoginView 的视图中
  • 类似这样的事情struct Controller: View { var body: some View { LoginView() .edgesIgnoringSafeArea(.bottom) } } 仍然无法正常工作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-09-27
  • 1970-01-01
  • 1970-01-01
  • 2012-09-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多