ios 7 drawViewHierarchyInRect:afterScreenUpdates:仅限iPad上的黑屏

时间:2014-02-12 14:28:15

标签: ios iphone objective-c ipad ios7

我有非常奇怪的情况......我正在尝试通过调用contentSize来滚动视图(drawViewHierarchyInRect: afterScreenUpdates:超过屏幕边界三次)捕获内容,如下所示:

+ (UIImage *) imageFromScrollView: (UIScrollView *) scrollView {

    UIGraphicsBeginImageContext(size);

    [view drawViewHierarchyInRect: CGRectMake(0, 0, scrollView.contentSize.width, scrollView.contentSize.height)
               afterScreenUpdates: YES];

    UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();  

    return image;  
}

适用于:iPhone设备,iPhone和iPad模拟器,但可在iPad上运行设备。你有过类似的问题吗?我将不胜感激任何帮助!

2 个答案:

答案 0 :(得分:2)

使用

UIGraphicsBeginImageContextWithOptions(size, NO, [UIScreen mainScreen].scale);

NO在这里很重要,因为它返回一个非不透明的图像。

答案 1 :(得分:-1)

此代码适用于我。

UIImage *image = [SnapShotter snapShotEntireScrollingView:self.receiptTableView];


+ (UIImage *)snapShotEntireScrollingView:(UIScrollView *)view
{
    return [self snapShotEntireScrollingView:view withEdgeInsets:UIEdgeInsetsZero];
}


+ (UIImage *)snapShotEntireScrollingView:(UIScrollView *)view withEdgeInsets:(UIEdgeInsets)insets
{
    CGRect currentFrame = view.frame;

    CGRect fullFrame = view.frame;
    fullFrame.size.width = MAX(currentFrame.size.width, view.contentSize.width);
    fullFrame.size.height = MAX(currentFrame.size.height, view.contentSize.height);
    view.frame = fullFrame;

    UIImage *image = [self snapShotView:view withEdgeInsets:insets];

    view.frame = currentFrame;
    return image;
}