gpt4 book ai didi

iphone - 将非事件 UIView 捕获为 UIImage

转载 作者:行者123 更新时间:2023-12-03 21:03:29 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com