如何获得类似截屏效果的闪屏效果?

How to obtain a screen flash effect like screen capture effect?

请问有什么方法可以实现某个NSView按需截图时的闪屏效果吗?我的问题不是 flashing screen programatically with Swift (on 'screenshot taken') 的重复,因为我需要 osx 的解决方案,而不是 ios 并且方法不同。

实现此目的的方法是创建一个与屏幕大小相同且颜色为黑色的新 UIView,将其添加到您的视图的子视图,然后将 alpha 设置为零(将持续时间设置为达到预期效果)完成后从超级视图中删除视图。

我在我的许多项目中都使用过这种技术,而且效果非常好。您可以调整视图的背景颜色来自定义 Flash 的外观。

类似这样的方法可能有效

func showScreenshotEffect() {
    let snapshotView = UIView()
    snapshotView.translatesAutoresizingMaskIntoConstraints = false
    view.addSubview(snapshotView)
    // Activate full screen constraints
    let constraints:[NSLayoutConstraint] = [
        snapshotView.topAnchor.constraint(equalTo: view.topAnchor),
        snapshotView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
        snapshotView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
        snapshotView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor)
    ]
    NSLayoutConstraint.activate(constraints)
    // White because it's the brightest color
    snapshotView.backgroundColor = UIColor.white
    // Animate the alpha to 0 to simulate flash
    UIView.animate(withDuration: 0.2, animations: { 
        snapshotView.alpha = 0
    }) { _ in
        // Once animation completed, remove it from view.
        snapshotView.removeFromSuperview()
    }
}