下面的代码运行良好,但只抓取屏幕上可见的UIView。 我如何获取当前未显示的UIView?
谢谢!
//Take a screenshot of the view...
UIGraphicsBeginImageContext(View_1.frame.size);
[View_1.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *View_1 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(View_1, nil, nil, nil);
//...and attach it as an image to the email
NSData *myData3 = UIImagePNGRepresentation(View_1);
[picker addAttachmentData:myData3 mimeType:@"image/png" fileName:@"screenshot2"];
答案 0 :(得分:2)
如果您的意思是隐藏在view.hidden = YES;
中,那么您将无法绘制它,而不是隐藏它,您可以将其从超级视图中删除,或者甚至在绘制之前调用view.hidden = NO;
在绘制之后view.hidden = YES;
例如
//Take a screenshot of the view...
UIGraphicsBeginImageContext(View_1.frame.size);
//Set it to visible
View_1.hidden = NO;
[View_1.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *View_1 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(View_1, nil, nil, nil);
//Hide it again
View_1.hidden = YES;
//...and attach it as an image to the email
NSData *myData3 = UIImagePNGRepresentation(View_1);
[picker addAttachmentData:myData3 mimeType:@"image/png" fileName:@"screenshot2"];