【问题标题】:How to obtain a screen flash effect like screen capture effect?如何获得类似截屏效果的闪屏效果?
【发布时间】:2017-02-14 15:56:51
【问题描述】:

有没有什么方法可以根据需要为某个 NSView 获得像在截屏时产生的那样的闪屏效果?我的问题不是 flashing screen programatically with Swift (on 'screenshot taken') 的重复,因为我需要 osx 的解决方案,而不是 ios 并且方法不同。

【问题讨论】:

标签: swift macos animation screenshot nsview


【解决方案1】:

这样的事情可能会奏效

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()
    }
}

【讨论】:

    【解决方案2】:

    实现这一点的方法是创建一个与屏幕大小相同且颜色为黑色的新 UIView,将其添加为视图的子视图,然后将 alpha 设置为零(玩弄持续时间以实现所需的效果)完成后从超级视图中删除视图。

    我在我的许多项目中都使用了这种技术,它就像一种魅力。您可以使用视图的背景颜色来自定义 Flash 的外观。

    【讨论】:

      猜你喜欢
      • 2020-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多