Tell me more ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I have a problem that I can't seem to fix. I am trying to take a screen-shot of a UIScrollView (including off-screen content) but when the view is long the renderInContext doesn't get all the contents of the scroll view.

The produced image dimensions are correct but the rendered data appears to be missing chunks (or Tiles) of the display leaving white space where those chunks should be. The missing blocks are from the content in a UIWebView, which I believe extends UIWebTileView and could explain the missing tiles or blocks?

It doesn't happen everytime, it appears to only happen when the UIWebView's height is fairly large.

Here is the code that I am using:

UIGraphicsBeginImageContext(scrollView.contentSize);
{
    CGPoint savedContentOffset = scrollView.contentOffset;
    CGRect savedFrame = scrollView.frame;


    //hide the scroll bars
    [scrollView setShowsHorizontalScrollIndicator:NO];
    [scrollView setShowsVerticalScrollIndicator:NO];


    scrollView.contentOffset = CGPointZero;
    scrollView.frame = CGRectMake(0, 0, scrollView.contentSize.width, scrollView.contentSize.height);
    //adjust layer for cut-off
    CALayer *coreLayer = scrollView.layer;
    coreLayer.bounds = CGRectMake(0, 0, scrollView.contentSize.width, scrollView.contentSize.height);
    [coreLayer renderInContext: UIGraphicsGetCurrentContext()]; 
    //[scrollView.layer renderInContext: UIGraphicsGetCurrentContext()];
    image = UIGraphicsGetImageFromCurrentImageContext();

    scrollView.contentOffset = savedContentOffset;
    scrollView.frame = savedFrame;


    //reset the scroll bars to default
    [scrollView setShowsHorizontalScrollIndicator:YES];
    [scrollView setShowsVerticalScrollIndicator:YES];
}
UIGraphicsEndImageContext();

Has anyone ever experienced this issue before? How would I go about fixing it? Should I try to get the UIWebView's layer and and get the graphics from that?

Any help would be greatly appreciated!

Thanks!

share|improve this question
1  
Is this more for SO? – FossilizedCarlos Apr 5 '12 at 18:24
@PetroEkos Yes it is. – daviesgeek Apr 5 '12 at 18:38

closed as off topic by jaberg, gentmatt, daviesgeek, CajunLuke, Nathan Greenstein Apr 5 '12 at 23:52

Questions on Ask Different are expected to relate to Apple hardware or software within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.