【发布时间】:2021-12-16 04:01:32
【问题描述】:
在嵌套视图中使用 .contextMenu 视图修饰符时似乎存在问题。
这是显示问题的示例代码:
import SwiftUI
enum SampleEnum: String, CaseIterable {
case one, two, three, four
}
struct ContentView: View {
var body: some View {
Form {
Section {
VStack {
HStack {
ForEach(SampleEnum.allCases, id:\.self) { id in
Text(id.rawValue)
.contextMenu {
Button {
print("Change country setting")
} label: {
Label("Choose Country", systemImage: "globe")
}
}
}
}
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
因此,由于选择了整个部分/堆栈,因此似乎无法在单个文本视图上执行上下文菜单。
有没有办法让 contextMenu 在这种嵌套布局中的单个文本视图上工作?
【问题讨论】:
-
可能与表单有关。试试Vstack,看看有没有区别
-
.contextMenu已弃用
标签: swiftui contextmenu