如何影响 SwiftUI contextMenu 位置?

How do I influence SwiftUI contextMenu placements?

提问人:J. Edgell 提问时间:5/18/2021 更新时间:5/18/2021 访问量:355

问:

如何影响 contextMenu 在 SwiftUI 中的位置?我似乎得到了与我想要的完全相反的结果。我想要的是上下文菜单与所附照片中的箭头所示的文本对齐。图像上下文菜单运行良好,但文本部分是挑战所在。我也尝试过改变对齐方式,但没有喜悦......

struct ContextMenuView: View {
    var body: some View {
        HStack {
            ScrollView(.vertical, showsIndicators: false) {
                HStack {
                    VStack() {
                        Text("Test").font(.footnote)
                        Text("Test").lineLimit(30)
                    }
                    .frame(minWidth: 0, maxWidth: .infinity, alignment: .trailing)
                    .padding()
                    .background(Color.blue)
                    .cornerRadius(10)
                    .contentShape(RoundedRectangle(cornerRadius: 10, style: .continuous))
                    .contextMenu() {
                        Button {
                            print("Delete")
                        } label: {
                            Label("Delete this message", systemImage: "trash")
                        }
                    }
                    Image(systemName: "person.fill")
                    .contextMenu() {
                        Button {
                            print("Send")
                        } label: {
                            Label("Send private message", systemImage: "mail")
                        }
                    }
                }.padding()
            
                HStack {
                    Image(systemName: "person.fill")
                    .contextMenu() {
                        Button {
                            print("Send")
                        } label: {
                            Label("Send private message", systemImage: "mail")
                        }
                    }
                    VStack() {
                        Text("Test").font(.footnote)
                        Text("Test").lineLimit(30)
                    }
                    .frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
                    .padding()
                    .background(Color.blue)
                    .cornerRadius(10)
                    .contentShape(RoundedRectangle(cornerRadius: 10, style: .continuous))
                    .contextMenu() {
                        Button {
                            print("Delete")
                        } label: {
                            Label("Delete this message", systemImage: "trash")
                        }
                    }
                }.padding()
            }
        }
    }
}

enter image description here enter image description here

enter image description here

SWIFTUI的 上下文菜单

评论


答: 暂无答案