SwiftUI:删除拖动视图的背景

vie*_*dev 2 macos ios swift swiftui

我有一个可以拖动的圆角视图。开始拖动后,白色半透明背景视图将在角落可见。如何将其删除?

我尝试使用.contentShapeand.clipShape但这并不能解决问题。在 UIKit 中,我曾经UIDragPreviewParameters剪辑预览,但 SwiftUI 中似乎没有这样的东西。有任何想法吗?

代码:

RoundedRectangle(cornerRadius: 25, style: .continuous)
    .foregroundColor(.blue)
    .frame(width: 100, height: 100)
    .contentShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
    .onDrag {
        NSItemProvider()
    }
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Asp*_*eri 7

您需要.dragPreview输入内容形状,例如

RoundedRectangle(cornerRadius: 25, style: .continuous)
    .foregroundColor(.blue)
    .frame(width: 100, height: 100)
    .contentShape(.dragPreview, RoundedRectangle(cornerRadius: 25, style: .continuous))
Run Code Online (Sandbox Code Playgroud)