如何在按钮.popover TextEditor 中获取空间?

问题描述 投票:0回答:1

当我在文本编辑器中按键盘上的空格时,应用程序控制台中会打印“父按钮单击”,但空格不会放入文本编辑器中。其他角色不存在这样的问题。在这种情况下如何在 TextEditor 中获取空间?

import SwiftUI

struct ContentView: View {
    @State private var showPopoverComment = false
    
    var body: some View {
        Button(action: {
            print("parent button click")
        }) {
            VStack {
                Button("child button", action: {showPopoverComment = true})
                    .popover(isPresented: $showPopoverComment) {
                        EditCommentView()
                            .frame(width: 100, height: 100)
                    }
                // other views ...
            }
        }.buttonStyle(.plain)
    }
}

struct EditCommentView: View {
    @State var comment: String = ""
    var body: some View {
        TextEditor(text: $comment)
    }
}

enter image description here

swiftui
1个回答
0
投票

.popover
移到父按钮之外。

struct ContentView: View {
    @State private var showPopoverComment = false
    
    var body: some View {
        Button(action: {
            print("parent button click")
        }) {
            VStack {
                Button("child button", action: {showPopoverComment = true})
                // other views ...
            }
        }.buttonStyle(.plain)
        
        .popover(isPresented: $showPopoverComment) {  // <--- here
            EditCommentView()
                .frame(width: 100, height: 100)
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.