1

I looked at this code here, which lets you take a screenshot of either the top visible portion of a UIScrollView or of the whole UIScrollView:

Getting a screenshot of a UIScrollView, including offscreen parts

What I want is to take a screenshot of just the portion from contentOffset onwards, as the UIScrollView can be quite long and thus it would take a while to take a screenshot of it. Is it possible to do this?

Community
  • 1
  • 1
Andrew
  • 15,935
  • 28
  • 121
  • 203

2 Answers2

1

The solution you mentioned basically resize the scroll view to match the size of its content, and therefore the entire content will be rendered without a scroll and then captured.

If you want to apply the same solution, you can resize the scroll view to match the size of the visible content + the size of remaining content til the end.

So try to replace those lines:

_scrollView.contentOffset = CGPointZero;
_scrollView.frame = CGRectMake(0, 0, 
                    _scrollView.contentSize.width, 
                    _scrollView.contentSize.height);

With:

//_scrollView.contentOffset = CGPointZero; // Don't change the offset
_scrollView.frame = CGRectMake(0, 0, 
                    _scrollView.contentSize.width, 
                    _scrollView.contentSize.height - _scrollView.contentOffset);
Hejazi
  • 16,587
  • 9
  • 52
  • 67
0

I had asked similar question before Taking screenshot of Part of Screen

You can take screenshot of what the user is seeing in terms of 320 x 480 but you cannot take screenshot of a portion of the screen. X and Y coordinates have absolutely no effect on where the screenshot starts/stops.

Community
  • 1
  • 1
Sam B
  • 27,273
  • 15
  • 84
  • 121