这是简化的代码:
var body: some View {
Section(header: Text("Personal Data").position(x:45, y: 17)) {
Form {
VStack {
TextField("Title", text: self.$title)
.disabled(true)
.overlay(
Button("", action: {
self.showTitles = true
}))
.popover(isPresented: self.$showTitles, attachmentAnchor: .point(.bottom)) { EmptyView() }
Divider()
TextField("Name", text: $firstName)
Divider()
TextField("Last Name", text: $lastName)
}
.padding()
.padding(.bottom, -7)
.overlay(
RoundedRectangle(cornerRadius: 6.0)
.stroke(Color.secondary, lineWidth: 1.0)
.opacity(0.3)
)
}
}
}
在添加 VStack 之前,它可以按我的意愿工作,尽管我需要它才能放置 Dividers。我试图用 VStack 包装单个 TextField 并使用 Group 来查看我是否只能在第一个 TextField 上覆盖按钮,但似乎没有任何效果。我必须为此目的使用 GeometryReader 吗?
如果有人能提供一些见解,我将不胜感激。