6
在iphone上,是否可以“屏幕截图”一个UIView及其所有子视图?如果可能的话,怎么样?一个视图的iPhone屏幕截图
在iphone上,是否可以“屏幕截图”一个UIView及其所有子视图?如果可能的话,怎么样?一个视图的iPhone屏幕截图
我发现了这一点,但还没有尝试过自己:
http://reusablesnippets.posterous.com/capture-uiview
这里您可以找到使用-renderInContext:
http://developer.apple.com/mac/library/documentation/GraphicsImaging/Reference/CALayer_class/Introduction/Introduction.html#//apple_ref/doc/uid/TP40004500-CH1-SW120
编辑
我上面转化的代码到UIView类别。 这样称呼:[aView saveScreenshotToPhotosAlbum];
#import <QuartzCore/QuartzCore.h>
- (UIImage*)captureView {
CGRect rect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
- (void)saveScreenshotToPhotosAlbum {
UIImageWriteToSavedPhotosAlbum([self captureView], nil, nil, nil);
}
这将适用于普通图层。 OpenGl图层不会显示在屏幕截图中。 UIWebview屏幕截图将失败,如果HTML将-transform css。 – 2mia 2012-11-07 14:01:23