Ios 7 drawViewHierarchyInRect: afterScreenUpdates: black screen only on iPad

I have a very strange situation ... I am trying to grab content from a scroll (which contentSizeexceeds the borders of the screen three times) by calling drawViewHierarchyInRect: afterScreenUpdates:, as shown below:

+ (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;  
}

He works for: device iPhone, iPhone and iPad Simulator, but it does not work on the iPad device . Have you ever encountered a similar problem? I would be grateful for any help!

+4
source share
2 answers

Using

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

NO is important here, since it returns an opaque image.

+2
source

.

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;
}
-1

Source: https://habr.com/ru/post/1526561/


All Articles