Swift获取屏幕快照

 1 // 获取屏幕快照
 2     private func screenShot() -> UIImage{
 3         let window = UIApplication.shared.keyWindow!
 4         UIGraphicsBeginImageContext(window.size)
 5         
 6         // 绘图
 7         window.drawHierarchy(in: window.bounds, afterScreenUpdates: false)
 8         
 9         // 从图形上下文获取图片
10         let image = UIGraphicsGetImageFromCurrentImageContext()!
11 
12         UIGraphicsEndImageContext()
13         
14         return image
15     }
原文地址:https://www.cnblogs.com/panda1024/p/6204160.html