即使指定 contentShape 后,ContextMenu 仍使用不正确的cornerRadius

5 contextmenu ios swift swiftui

struct CardView: View {
    private var name: String = "Random Name"
    private var color: Color = Color.red
    
    private var CardContent: some View {
        HStack(alignment: .top) {
            Text(name)
                .font(.system(size: 16, weight: .medium, design: .rounded))
                .frame(width: 110, height: 80, alignment: .top)
        }
        .padding(.top, 20)
        .frame(width: 200, height: 190, alignment: .top)
        .background(color)
        .clipShape(RoundedRectangle(cornerRadius: 30, style: .continuous))
    }
    
    var body: some View {
        CardContent
            .contentShape(RoundedRectangle(cornerRadius: 30, style: .continuous))
            .contextMenu {
                Button(action:{}){
                    HStack {
                        Image(systemName: "trash")
                            .foregroundColor(Color.red)
                        Text("Delete")
                    }
                }
        }
        .shadow(color: color.opacity(0.5), radius: 10, x: 10, y: 10)
    }
}
Run Code Online (Sandbox Code Playgroud)

当我长按时,视图被错误地剪切:

在此输入图像描述]

另外,为什么垃圾桶图像不是红色的?

这是一个ContextMexu怪癖吗?

小智 0

结果 iOS 13.6 模拟器出现了这个奇怪的现象,用 Xcode 12 切换到 iOS 14 后问题就消失了。