[英]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.