[英]SwiftUI, cannot dismiss sheet after the keyboard
在 SwiftUI 中,我打开一个CommentsView
表,如下所示:
@State private var selectedCategory: Category?
Button(category.name) {
selectedCategory = category
}
.sheet(item: $selectedCategory) { category in
CommentsView(category: category)
}
CommentsView
查看:
struct CommentsView: View {
@Environment(\.presentationMode) private var presentationMode
@State private var enteredComment: String = ""
let category: Category
var body: some View {
VStack {
TextField("Add a comment", text: $enteredComment)
.textFieldStyle(RoundedBorderTextFieldStyle())
Button("Close") {
presentationMode.wrappedValue.dismiss()
}
}
}
}
问题是:在我关注文本字段并看到键盘后,我无法关闭CommentsView
。 在聚焦之前,“关闭”按钮按预期工作。
将 .sheet 的位置更改为顶部 VStack/HStack 或 ZStack,而不是按钮视图
.sheet(item: $selectedCategory) { category in
CommentsView(category: category)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.