我在UIScrollView中有一个UIPickerView。当我渲染图像时,照片中的UIPickerView被打乱了。
这是图片: Output of the image with a scrambled UIPickerView
这是我正在使用的代码:
- (IBAction) renderScrollViewToImage
{
UIImage* image = nil;
[self.scrollView removeFromSuperview];
//UIGraphicsBeginImageContext(self.scrollView.contentSize);
UIGraphicsBeginImageContextWithOptions(self.scrollView.contentSize, YES, 0);
{
CGPoint savedContentOffset = self.scrollView.contentOffset;
CGRect savedFrame = self.scrollView.frame;
self.scrollView.contentOffset = CGPointZero;
self.scrollView.frame = CGRectMake(0, 0, self.scrollView.contentSize.width, self.scrollView.contentSize.height);
[self.scrollView.layer renderInContext: UIGraphicsGetCurrentContext()];
image = UIGraphicsGetImageFromCurrentImageContext();
self.scrollView.contentOffset = savedContentOffset;
self.scrollView.frame = savedFrame;
}
UIGraphicsEndImageContext();
[self.view addSubview:scrollView];
}