Pregunta

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?

¿Fue útil?

Solución 2

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.

Otros consejos

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top