如何在连接时使用键盘移动视图,类似于 .toolbar

How to move a view with the keyboard while attached similar to .toolbar

我想让 TextEditor1 出现在应用程序的 bottom 上,然后当用户点击 TextEditor1 键入消息时,TextEditor1应该附加到 keyboard 并随之向上移动。我使用了以下代码,它通过 .toolbar 附加到它,但不知道如何使 TextEditor1 留在应用程序的底部等,然后用键盘向上移动。附上图片以作进一步说明。

import SwiftUI


struct ContentView: View {
    
    @State var textTyped: String = "this is textttt"
    
    var body: some View {
        TextEditor (text: $textTyped)
            .toolbar {
                        ToolbarItemGroup(placement: .keyboard) {
                           
                            TextEditor1()
                            
                            
                        }
                     
            }
            .frame(height: 200, alignment: .leading)
            .padding(.horizontal, 10)
}
}

struct TextEditor1: View {
    
    @State var textTyped: String = "this is textttt"
    
    var body: some View {
        TextEditor (text: $textTyped)
            .frame(height: 200, alignment: .leading)
            .padding(.horizontal, 10)
                     
            }
            
}

这是你想要的吗?我还放了一个彩色的 .background() 来查看 TextEditor 的轮廓。我发现能够可视化视图的范围会有所帮助。

struct ContentView: View {
    @State var textTyped: String = "this is textttt"
    
    var body: some View {
        VStack {
            Spacer()
            TextEditor (text: $textTyped)
                .frame(height: 200, alignment: .leading)
//                .padding(.horizontal, 10)
                .padding()
                .background(Color.yellow.opacity(0.2))
        }
    }
}