ios Sprite Kit 截图? [英] ios Sprite Kit screengrab?

查看:17
本文介绍了ios Sprite Kit 截图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取其中包含 SKScene 的视图的屏幕截图.我使用的技术是:

I am trying to get a screen grab of a view that has a SKScene in it. The technique I am using is:

UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, scale);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

这适用于普通 UIView,但无论出于何种原因,它都会忽略 SKScene 中的所有精灵.

This works great with normal UIViews, but for whatever reason it is ignoring all the sprites in the SKScene.

我不确定这是否是一个错误,或者 Sprite Kit 的渲染是否与 UIGraphics 分开.

I'm not sure if this is a bug, or if Sprite Kit's rendering is separate from UIGraphics.

问题:当适用于 UIViews 的方式似乎不适用于 Sprite Kit 时,我如何获取 SKScene 的屏幕抓图,或者是否有人成功使用带有 Sprite Kit 的 UIGraphics 上下文?

Question: How do I get a screen grab of an SKScene when the way that worked for UIViews seems to not work with Sprite Kit, or has anyone had success using UIGraphics context with Sprite Kit?

推荐答案

你几乎拥有它,但问题如上面评论中所述.如果您想捕获 SKScene 内容,请尝试以下操作:

You almost have it, but the problem is as explained in the comment above. If you want to capture SKScene contents, try something like this instead:

UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, scale);
[self.view drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

解决方案基本上是使用新方法 drawViewHierarchyInRect:afterScreenUpdates 代替,这是我们目前最好的;请注意,它的速度并不快,因此实时执行此操作并不美观.

The solution is to basically use the new method drawViewHierarchyInRect:afterScreenUpdates instead, which is the best we have for now; note, it's not exactly speedy, so doing this in realtime will not be pretty.

这篇关于ios Sprite Kit 截图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆