iphone - 将非事件 UIView 捕获为 UIImage

标签 iphone ios5 ios4

下面的代码运行良好,但仅抓取屏幕上可见的 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"];   

最佳答案

如果您的意思是像 view.hidden = YES; 中那样隐藏,那么您将无法绘制它,您可以将其从 super View 中删除,甚至调用 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"];

关于iphone - 将非事件 UIView 捕获为 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11061850/

相关文章:

objective-c - iphone 5 的 xcode4.2 中的自动引用计数与 __bridge 冲突

iphone - 父 View Controller 中是否有一个委托(delegate)在模态视图被关闭后被调用?

ios - 同步 AB 地址簿条目

ios - 在 iPhone 上调试卡住 safari

c# - 如何选择多张照片?

iphone - 导航栏后退按钮,文本未居中对齐

iphone - "_OBJC_CLASS_$_CATransaction, referenced from:"编译时错误是什么意思?

iphone - 如何检查您的 iPhone 联系人列表中的人是否安装了应用程序?

iphone - 没有标题动画的pushViewController

iphone - IOS5:非运行状态下的图标徽章