嗨,我正在制作一个游戏,我已经添加了一个分享按钮到游戏。我希望用户能够共享一条消息,网址,并在一条消息中彼此沿着截图。它的共享方面工作正常,一切都显示出来,除了屏幕截图本身显示为空白。这是我用来截图的代码:
let layer = UIApplication.sharedApplication().keyWindow!.layer
let scale = UIScreen.mainScreen().scale
UIGraphicsBeginImageContextWithOptions(layer.frame.size, false, scale);
layer.renderInContext(UIGraphicsGetCurrentContext())
let screenshot = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
UIImageWriteToSavedPhotosAlbum(screenshot, nil, nil, nil)
println("screenshot")
请帮助我解决这个问题,请确保使用Swift语言。此外,我使用SpriteKit技术,如果这使一个差异。我是新的编码,所以请非常清楚。非常感谢!
3条答案
按热度按时间mbjcgjjk1#
更新:Xcode 8.2.1 · Swift 3.0.2
您需要将import语句和这个扩展添加到游戏场景中:
tag5nh1u2#
在WWDC 2015中,UIVisualEffectView中的新功能,一个解决方案被“掩盖”,用于捕获包含振动标签和模糊的UIVisualEffectView的屏幕截图。经常出现的问题是,苹果的截图API往往不会捕获UIVisualEffect,导致视图的截图没有视觉效果。根据WWDC 2015的解决方案涉及在窗口/屏幕处捕获快照;不幸的是,没有显示示例代码。以下是我自己的实现:
注意:此快照代码仅在调用ViewDidAppear后才有效。
jhiyze9q3#
在我的例子中,我在用scandit SDK扫描护照时进行了屏幕截图,结果是一个空白(黑色)图像,然后我从scandit**图像缓冲区中获取图像并使用该图像。
您可能会在应用程序中使用一些相机SDK,这些SDK会阻止屏幕截图并返回空白(黑色)图像。