ios - ios如何截取不可见部分的屏幕截图?

标签 ios iphone objective-c ipad ios6

我正在开发iOS应用程序,我需要捕获 View 并将彩信发送给特定的人。一切都工作正常。但是我面临着捕获不可见的问题(为了更多说明,我附上了图片)。

enter image description here

我得到了可见 View 的屏幕截图。如何解决这个问题?有什么方法可以达到我的要求吗?我得到的图像是

enter image description here

我用的截图代码是

UIGraphicsBeginImageContext(webview_pdf.bounds.size);
[webview_pdf.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *pdfImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

好的建议值得赞赏。提前致谢。!

最佳答案

终于找到解决办法了

+ (UIImage *) imageFromWebView:(UIWebView *)view
{
    // tempframe to reset view size after image was created
    CGRect tmpFrame = view.frame;

    // set new Frame
    CGRect aFrame = view.frame;
    aFrame.size.height = [view sizeThatFits:[[UIScreen mainScreen] bounds].size].height;
    view.frame = aFrame;

    // do image magic
    UIGraphicsBeginImageContext([view sizeThatFits:[[UIScreen mainScreen] bounds].size]);

    CGContextRef resizedContext = UIGraphicsGetCurrentContext();
    [view.layer renderInContext:resizedContext];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    // reset Frame of view to origin
    view.frame = tmpFrame;
    return image;
}

关于ios - ios如何截取不可见部分的屏幕截图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21678321/

相关文章:

ios - 让应用程序屏幕的大部分区域都覆盖着黑色是否可以节省电池电量?

iphone - Paypal iphone超时错误一次又一次

iOS StoreKit - 模拟不完整和中断的应用内购买

objective-c - 将字符串中出现的两个字符相互替换

ios - 我正在使用 dchohfi 开发的 KeyValueObjectMapping。但在映射 JSON 对象数组时面临问题

ios - 如果文本是阿拉伯语,则使 UILabel 文本右对齐

ios - 减慢 UIScrollView 滚动

android - 为什么推送通知服务器准确地向客户端发送消息

iphone - 具有动态高度的 UILabel 不适用于 iOS 中的相同字符串

objective-c - 如何禁用水平滚动并且页面将在使用 UIScrollView 的分页中单击时更改?