英文:
I have bug with ContextMenu on rounded views in SwiftUI
问题
我在调用上下文菜单时,我的视图显示存在问题。没有上下文菜单时,视图显示正常,但出现问题时似乎存在上下文菜单。如果有人有关于如何解决这个问题的建议,我将非常感激。
TravelView(travel: travel)
.contextMenu {
VStack {
Button(action: {}) {
Label("Edit", systemImage: "pencil")
}
}
}
TravelView如下:
VStack {
// 一些代码
}
.background(Color.green.opacity(0.8))
.cornerRadius(20)
我需要去掉胶囊上的边框和字体上的阴影。
英文:
I'm experiencing an issue with the display of my View when I invoke the context menu. The View appears correctly without the context menu, but there seems to be a problem when it's present. If anyone has any suggestions on how to fix this, I would greatly appreciate it.
TravelView(travel: travel)
.contextMenu {
VStack {
Button(action: {}) {
Label("Edit", systemImage: "pencil")
}
}
TravelView looks like
VStack{
// some code
}
.background(Color.green.opacity(0.8))
.cornerRadius(20)
.shadow(color: .black.opacity(0.5), radius: 5, x: 0, y: 2)
I need to remove the frames on the capsule and the shadows on the font
答案1
得分: 2
.contentShape(.contextMenuPreview, RoundedRectangle(cornerRadius: 20))
请放在.contextMenu
修饰符之前,就像这样:
TravelView(travel: travel)
.contentShape(.contextMenuPreview, RoundedRectangle(cornerRadius: 20)) // 这里的20是在你的 `TravelView` 中使用的圆角半径
.contextMenu {
VStack {
Button(action: {}) {
Label("编辑", systemImage: "pencil")
}
}
}
希望能解决问题。
英文:
Add
.contentShape(.contextMenuPreview, RoundedRectangle(cornerRadius: 20))
just before the .contextMenu
modifier like this:
TravelView(travel: travel)
.contentShape(.contextMenuPreview, RoundedRectangle(cornerRadius: 20)) // this 20 is the corner radius used in your `TravelView`
.contextMenu {
VStack {
Button(action: {}) {
Label("Edit", systemImage: "pencil")
}
}
Hope it solves the issue.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论