简体   繁体   English

在 SwiftUI 中显示键盘上方视图

[英]Present View above keyboard in SwiftUI

I'd like to be able to present a view the is aligned to the bottom of the top of the keyboard regardless of the device.无论设备如何,我都希望能够呈现与键盘顶部底部对齐的视图。 I'm trying to use strictly SwiftUI for this as I don't know UIKit.我正在尝试严格使用 SwiftUI,因为我不知道 UIKit。 I have attached the picture of said solution.我附上了上述解决方案的图片。

Can someone show me a coded solution that would work in SwiftUI to achieve this basic result?有人可以向我展示一个可以在 SwiftUI 中工作以实现此基本结果的编码解决方案吗? Thanks.谢谢。

Google Tasks 应用程序屏幕截图

Just create a ToolbarItem on the .keyboard .只需在ToolbarItem上创建一个.keyboard

Code:代码:

struct ContentView: View {
    @State private var text = "Hello world!"

    var body: some View {
        TextField("Text", text: $text)
            .toolbar {
                ToolbarItem(placement: .keyboard) {
                    Text("Keyboard item")
                }
            }
    }
}

Result:结果:

结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM