简体   繁体   English

iOS 对tableview进行截图

[英]iOS taking a screenshot of tableview

So I am creating an iPad app where I need to take a screenshot of a tableview and display it later, similar to iPad safari tabs page.所以我正在创建一个 iPad 应用程序,我需要在其中截取表格视图并稍后显示,类似于 iPad safari 选项卡页面。 I need to take the screenshot in both orientations without actually changing the orientation.我需要在两个方向上截取屏幕截图而不实际改变方向。 How can I archieve this?我怎样才能归档这个?

What you are describing is beyond the limits of any "screenshot."您所描述的超出了任何“屏幕截图”的限制。 You will need to manually generate the images for the table view.您将需要手动生成表格视图的图像。 If the view is simple (ie some text, separators, etc), you could do this using CoreGraphics or something of the sort to draw the image from scratch.如果视图很简单(即一些文本、分隔符等),您可以使用 CoreGraphics 或类似的东西从头开始绘制图像。 I maintain an open source class called ANImageBitmapRep which allows for easy pixel-level, and context level image manipulation.我维护了一个名为ANImageBitmapRep的开源 class,它允许轻松进行像素级和上下文级图像操作。 In this case, you will most likely be using core graphics, but here's how you would generate a context in the first place:在这种情况下,您很可能会使用核心图形,但首先是生成上下文的方式:

ANImageBitmapRep * irep = [[ANImageBitmapRep alloc] initWithSize:BMPointMake(myWidth, myHeight)];
CGContextRef context = [irep context];
// ...
// use context here to manually generate your "screenshot."
// ...
[irep setNeedsUpdate]; // tell the image bitmap rep to update its image
UIImage * savedImage = [irep image]; // get a UIImage for storing
[irep release]; // free the memory

A small tutorial on drawing with CoreGraphics can be found at http://idevhub.com/exploring-iphone-graphics-part-1/ .可以在http://idevhub.com/exploring-iphone-graphics-part-1/找到有关使用 CoreGraphics 绘图的小教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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