我正在尝试截取我的应用的屏幕截图,然后共享它。
我遇到的问题是,当我截取屏幕截图并将其保存到“照片”应用程序时,保存的图像完全是黑色的(而不是我的应用程序的屏幕截图)。
如何获取屏幕快照作为我的应用程序?我想念什么?
func takeScreenshot() {
let bounds = UIScreen.main.bounds
UIGraphicsBeginImageContextWithOptions(bounds.size, true, 0.0)
self.view.drawHierarchy(in: bounds, afterScreenUpdates: false)
let img = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
let activityViewController = UIActivityViewController(activityItems: [img!], applicationActivities: nil)
self.present(activityViewController, animated: true, completion: nil)
}
应用程序是一个屏幕。迅捷5xCode 10
我曾尝试浏览其他类似的StackOverflow问题,并将我的代码调整为它们的问题,但得到的结果相同。打墙然后在这里尝试。
感谢您的帮助!
尝试更改
afterScreenUpdates: false
收件人
afterScreenUpdates: true
那样,将有一些要快照的图形。