Cocoa touch Can';t获取要在UIImageView中显示的UIView屏幕截图

Cocoa touch Can';t获取要在UIImageView中显示的UIView屏幕截图,cocoa-touch,uiview,uiimageview,uiimage,uikit,Cocoa Touch,Uiview,Uiimageview,Uiimage,Uikit,以下是获取视图屏幕截图的代码: if (NULL != UIGraphicsBeginImageContextWithOptions){ UIGraphicsBeginImageContextWithOptions(pagedScrollView.frame.size, NO, [[UIScreen mainScreen] scale]); }else{ UIGraphicsBeginImageContext(pagedScrollView.frame.size); } [pa

以下是获取视图屏幕截图的代码:

if (NULL != UIGraphicsBeginImageContextWithOptions){
    UIGraphicsBeginImageContextWithOptions(pagedScrollView.frame.size, NO, [[UIScreen mainScreen] scale]);
}else{
    UIGraphicsBeginImageContext(pagedScrollView.frame.size);
}

[pagedScrollView.layer renderInContext:UIGraphicsGetCurrentContext()];
screenshotImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

UIImageView *imageView = [[UIImageView alloc] initWithImage:screenshotImage];
imageView.frame = CGRectMake(imageView.frame.origin.x, imageView.frame.origin.y, imageView.frame.size.width, imageView.frame.size.height);
imageView.backgroundColor = [UIColor greenColor];
[self.view addSubview:imageView];
我100%确定我有正确的框架和正确的视图-
UIImageView
的大小,但问题是我无法将我的
UIImage
显示在
UIImageView

UIImageView
被添加到视图中,我在视图上看到一个绿色区域,但里面没有图像,有什么问题


我正在使用iOS 6和ARC。

我刚刚测试了在我的视图控制器视图上运行的代码,捕获和显示工作正常。这让我相信
pagedScrollView
可能为零,或者具有零帧


无论哪种方式,您都将从空白上下文创建一个图像,然后将其传递到您的图像视图,从而导致没有任何可见的图像。

事实证明,我一直在拍摄一个长
UIScrollView
的屏幕截图,我总是拍摄它的第一页-其中有很多页面,有时该层中什么都没有。结果还表明,
UIImage
从未被释放过,内存可以有效地存储几十个。

那么UIImage释放得如此之快而不停留在那里呢?有可能吗?我有很多,大约5个,我把它们都添加到
UIScrollView
。只有第一个留在那里,而我看不到其他的。