0

我在表单下有一个视图。当我输入文本字段时,视图卡在键盘顶部。

有问题的代码:

  // other stuff

  Form {
    Section {
      TextField("Enter your desired username", text: $page.username)
    }
    
    Section {
      Button(action: createUser) {
        Label("Sign Up", systemImage: "person.crop.circle.badge.plus")
      }
    }
  }
  
  // this is getting stuck on top of keyboard
  Group {
    Text("By signing up you agree to")
    // other stuff
  }

它看起来像什么:

有问题的错误

如您所见,“通过注册...”视图卡在键盘顶部。我怀疑它与菜单有关。

我该如何摆脱它?

4

1 回答 1

1

您是否在其他容器(如 VStack)中有表单和组?我认为您必须……如果是这样,解决方案是添加.ignoresSafeArea(.keyboard, edges: .bottom)到该容器中。

例如,

VStack {
    Form {
        ...
    }
    Group {
        ...
    }
}
.ignoresSafeArea(.keyboard, edges: .bottom)

应用ignoresSafeArea到组不起作用,因为它的容器(这里是 VStack)仍然可以通过键盘调整大小。如果添加ignoresSafeArea到您的容器有不良后果,请发布更多代码,以便我们了解情况。

于 2020-12-14T21:47:29.207 回答