简体   繁体   中英

Taking a screenshot of a view

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM