【发布时间】:2019-05-09 19:26:13
【问题描述】:
我正在尝试截取视觉模糊视图的屏幕截图。
根据文档
许多效果需要来自承载 UIVisualEffectView 的窗口的支持。尝试仅拍摄 UIVisualEffectView 的快照将导致快照不包含效果。要拍摄包含 UIVisualEffectView 的视图层次结构的快照,您必须拍摄包含它的整个 UIWindow 或 UIScreen 的快照。
所以我有以下层次结构
所以我正在拍摄完整的UIView 屏幕截图并尝试裁剪viewScreenShot 的矩形,但我无法做到这一点
到目前为止我尝试了什么
@IBAction func btnTapped(_ sender: Any) {
UIGraphicsBeginImageContextWithOptions(view.bounds.size, false, 0)
// self.viewScreenShot.layer.render(in: UIGraphicsGetCurrentContext()!)
self.view.drawHierarchy(in: CGRect(x: view.frame.origin.x, y: view.frame.origin.y, width: view.frame.width, height: view.frame.height), afterScreenUpdates: true)
let image = UIGraphicsGetImageFromCurrentImageContext()
let cgIImage = image?.cgImage?.cropping(to: CGRect(origin: viewScreenShot.frame.origin, size: viewScreenShot.frame.size))
let newImage = UIImage(cgImage: cgIImage!, scale: 1.0, orientation: UIImage.Orientation.up)
(self.view.viewWithTag(90) as? UIImageView)?.image = newImage
UIGraphicsEndImageContext()
}
输出
任何帮助将不胜感激
【问题讨论】: