1

I have a UIView within UIScrollView which is much higher than the screen. My code looks like this

UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, -500.0f, 320.0f, 2000.0f)];
[_scrollView addSubview:contentView];

and I want to capture an image of contentView

//Screen capture.
UIGraphicsBeginImageContextWithOptions(contentView.frame.size, NULL, 0.0f);
[self.view drawViewHierarchyInRect:contentView.bounds afterScreenUpdates:NO];
UIImage* viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

The above code works on simulator but not on actual device (iPod 5th gen)

If I capture the scrollView instead of contentView, it works ok, but only what's displayed on the screen will be captured. Any ideas?

codingrhythm
  • 1,456
  • 14
  • 26

2 Answers2

0

Use the scrollView.contentOffset. to get the frame of the View, which is currently on the screen.

Kumar KL
  • 15,315
  • 9
  • 38
  • 60
  • This is not what I want, I just want all contents within the scrollview can be captured all at once. I can only capture what's on the screen now, if I change the offset for drawViewHierarchyInRect, it will simply return a empty image – codingrhythm Feb 18 '14 at 22:06
0

Well, I reckon this may not be possible, as iOS won't draw off screen contents in order to gain more performance and battery life.

codingrhythm
  • 1,456
  • 14
  • 26