2010-08-15 38 views

Trả lời

9

Tôi thấy điều này, nhưng đã không cố gắng ra bản thân mình:

http://reusablesnippets.posterous.com/capture-uiview

Ở đây bạn tìm thấy sử dụng -renderInContext:http://developer.apple.com/mac/library/documentation/GraphicsImaging/Reference/CALayer_class/Introduction/Introduction.html#//apple_ref/doc/uid/TP40004500-CH1-SW120

chỉnh sửa

tôi chuyển mã ở trên để một danh mục trên UIView. gọi là như sau: [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); 

} 
+0

Điều này sẽ hoạt động đối với các lớp thông thường. Các lớp OpenGl sẽ không hiển thị trong ảnh chụp màn hình. Ảnh chụp màn hình UIWebview sẽ thất bại nếu html sẽ có -transform css. – 2mia

Các vấn đề liên quan