0

UIWebView - 将 Web 视图拉下然后将其转换为图像会导致顶部出现空白带而底部缺少信息?

使用此代码获取长而纤细的 Web 视图的图像屏幕截图。它工作正常,但如果我强行将其拉下然后截屏,根据我设置的背景颜色,我会在顶部得到一个空白带,在底部缺少相同的大小。

我不明白?这应该如何工作?

- (UIImage *)convertToImage
{

    // tempframe to reset view size after image was created
    CGRect originalFrame         = self.frame;

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

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

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

    UIGraphicsEndImageContext();

    // reset Frame of view to origin
    self.frame = originalFrame;

    return image;

}
4

1 回答 1

0

显然,Apple 决定 UIWebView 应该将其包含的滚动视图调整为插图,这是自 iOS 7 推出以来的情况。

要禁用此功能以及由此产生的头痛,我必须使用:

[self setAutomaticallyAdjustsScrollViewInsets = NO];

或者您可以在 Storyboard 中选择 Web 视图所在的视图控制器并取消选中此项:

调整滚动视图插图

于 2014-10-21T19:12:18.237 回答