ios 键盘工具栏按钮未显示

8cdiaqws  于 2023-08-08  发布在  iOS
关注(0)|答案(1)|浏览(116)

我正在使用example from HWS,但我没有运气得到按钮显示在键盘上方。
Xcode 13.2.1 /运行iOS 15.3.1的物理设备
这是已知问题吗?

import SwiftUI

struct KeyboardView: View {
    @State private var name = "Neil"

    var body: some View {
        TextField("Enter your name", text: $name)
            .textFieldStyle(.roundedBorder)
            .toolbar {
                ToolbarItemGroup(placement: .keyboard) {
                    Button("Click me!") {
                        print("Clicked")
                    }
                }
            }
    }
}

字符串

laawzig2

laawzig21#

1.将父视图放入NavigationStack或NavigationView中
1.将文本视图放在NavigationView(而不是堆栈)中

struct KeyboardView: View {
    @State private var name = "Neil"

    var body: some View {
        NavigationView {
            TextField("Enter your name", text: $name)
            .textFieldStyle(.roundedBorder)
            .toolbar {
                ToolbarItemGroup(placement: .keyboard) {
                    Button("Click me!") {
                        print("Clicked")
                    }
                }
            }
        }
    }
}

struct MyApp: App {
    var body: some Scene {
        WindowGroup {
            NavigationStack {
                KeyboardView()
            }
        }
    }
}

字符串
测试版本:Xcode 15 beta 5

相关问题