[英]Taking screenshot using Swift 5 returns a black image and not the app's screen
我正在尝试截取我的应用程序的屏幕截图,然后分享它。
我遇到的问题是,当我截取屏幕截图并将其保存到“照片”应用程序时,保存的图像是全黑的(而不是我的应用程序的屏幕截图)。
如何让屏幕截图成为我的应用程序的截图? 我错过了什么?
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)
}
应用程序是一个单一的屏幕。
斯威夫特 5
代码 10
我尝试浏览其他类似的 StackOverflow 问题并将我的代码调整为他们的代码,但得到了相同的结果。 撞墙并在这里尝试。
谢谢你的帮助!
尝试改变
afterScreenUpdates: false
到
afterScreenUpdates: true
这样就会有一些绘图要快照。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.