In iPhone application I want to generate a image of UIScrollView
whose content size is near about 600*41000
. If I use current graphic image context to capture the scroll view layer, then it only captures the visible part of the scroll view not the whole layer of that scroll view.
I am using the below code:
{
UIGraphicsBeginImageContext(CGSizeMake(600, 4100));
[scrollView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *img = [[UIImageView alloc]ini开发者_如何转开发tWithFrame:CGRectMake(00, 100, 710, 4100)];
img.image = viewImage;
[anotherScrollView addSubview:img];
}
Try to generate image not from UIScrollView
but from its content view. When you add some views to UIScrollView
with something like addSubview:
they become scroll's content ones. Of course, UIScrollView
can have more than one content view (just as any UIView
can have more than one subview) and this case it will be more difficult to render its layer. But in case of only one subview (content view) you can use something like (contentView
here is just some view, added to UIScrollView
before):
[contentView.layer renderInContext:UIGraphicsGetCurrentContext()];
or:
[[[[scrollView subviews] lastObject] layer] renderInContext:UIGraphicsGetCurrentContext()];
When you want to use more than one view, it will be easier (I think) to add one more "root" view and add others as that view's subviews: so you can also use the code above.
精彩评论