开发者

Taking a screenshot of a view

开发者 https://www.devze.com 2023-02-22 22:39 出处:网络
How does one take a screenshot of a view with code? I have read on some forums and there was a post made by an apple engineer and the code didnt work.

How does one take a screenshot of a view with code?

I have read on some forums and there was a post made by an apple engineer and the code didnt work.

Is there a built in way to do this or what is the correct way to screenshot a开发者_开发问答 view?


Apple just updated Technical Q&A QA1703 Screen Capture in UIKit Applications. I just put this in my code and it works well.


You can let the layer of the view render into a CGContextRef. This would be something like this:

[[myView layer] renderInContext:someContext];

You can then get the UIImage representation of the context and save it or so. However, please remark that this is kind of slow as the whole layer plus it sublayers have to be rendered again into the new context.

Don't forget to include and link against QuartCore for this.

0

精彩评论

暂无评论...
验证码 换一张
取 消