隐藏在图像后面的容器的程序屏幕截图

Programatic Screenshot of Container Hidden Behind an Image

所以我已经在使用此代码截取屏幕上可见的特定区域(table 单元格):

UIGraphicsBeginImageContextWithOptions(inputView.bounds.size, false, 0.0)
inputView.layer.renderInContext(UIGraphicsGetCurrentContext()!)
let image = UIGraphicsGetImageFromCurrentImageContext() as UIImage
UIGraphicsEndImageContext()
let cellSnapshot : UIView = UIImageView(image: image)

但是,现在我的目标更复杂了:

  1. 首先,以编程方式截取整个屏幕
  2. 将其呈现给用户,让他们暂时失明
  3. 然后我会在图片后面移动一些东西

棘手的部分... 虽然图像仍然隐藏了新设置,但我想 screenshot/capture 该视图排列的图像(包括每个视图在图像下)。

为什么要这样做? VC 没有改变,但我要在第二张图片中滑动,给人一种新安排的感觉新屏幕。

这可能吗?

下面是拍摄任何视图快照的代码!只需粘贴此函数并将其传递给您要捕获的视图!

let pictureOfView = snapshotOfView(passAViewHere)

func snapshotOfView (inputView: UIView) -> UIView {
    UIGraphicsBeginImageContextWithOptions(inputView.bounds.size, false, 0.0)
    inputView.layer.renderInContext(UIGraphicsGetCurrentContext()!)
    let image = UIGraphicsGetImageFromCurrentImageContext() as UIImage
    UIGraphicsEndImageContext()
    let cellSnapshot : UIView = UIImageView(image: image)
    cellSnapshot.layer.masksToBounds = false

    return cellSnapshot
}