1

在 SwiftUI 消息应用程序上显示我的键盘时,TextField 上升太多了。

我需要更改什么才能正确显示我的 TextField?

显示键盘时 - 堆栈有空格

这是我正在使用的代码:

var body: some View {
  VStack {
    //MARK: Users messasges
    List {
      OtherUserMessageCell(profilePicture: $profilePicture,
                           date: $date,
                           message: $message)

      MainUserMessageCell(date: $date,
                          message: $message)

      OtherUserMessageCell(profilePicture: $profilePicture,
                           date: $date,
                           message: $message)
    }

    ZStack {
      //MARK: Chat text field
      TextField(TextFieldName.message.rawValue,
                text: $composedMessage)
        .lineLimit(nil)
        .padding(EdgeInsets(top: 5, leading: 16, bottom: 5, trailing: 35))
        .overlay(RoundedRectangle(cornerRadius: 21)
          .stroke(lineWidth: 1)
          .foregroundColor(.primary)
      )
        .background(Color.white$black)

      HStack {
        Spacer()
        //MARK: Send message button
        Button(action: {}) {
          Image(systemName: ImageName.arrowUpCircleFill.rawValue)
            .resizable()
            .frame(width: 26, height: 26)
            .foregroundColor(.mainBlue)
        }
        .padding(.horizontal, 4)
      }
    }
    .padding()
    .padding(.bottom, keyboardHandler.currentHeight)
    .animation(.easeInOut)
  }
}
4

0 回答 0