在 Swift 中从 UITargetedPreview 中删除 BackgroundView

Sda*_*son 5 xcode swift

我正在尝试删除我的UITargetPreview. 我使背景颜色清晰,但是,您仍然可以看到背景的框架。

这是它目前的样子:

我目前有一个视图,其中包含文本容器和图像,这就是我用作UITargetedPreview.

有没有办法只显示图像和文本而不显示背景框架?

iUr*_*rii 2

有一个棘手的方法来隐藏阴影,为此,您应该_UIPlatterSoftShadowView在视图层次结构中找到具有类名的视图,然后将其隐藏。

func viewByClassName(view: UIView, className: String) -> UIView? {
    let name = NSStringFromClass(type(of: view))
    if name == className {
        return view
    }
    else {
        for subview in view.subviews {
            if let view = viewByClassName(view: subview, className: className) {
                return view
            }
        }
    }
    return nil
}

override func tableView(_ tableView: UITableView, willDisplayContextMenu configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionAnimating?) {
    DispatchQueue.main.async {
        if let window = UIApplication.shared.delegate?.window! {
            if let view = self.viewByClassName(view: window, className: "_UIPlatterSoftShadowView") {
                view.isHidden = true
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

注意:它没有记录内部类,可以随时进一步更改,但它现在可以在 ios 13/14 上运行。