【发布时间】:2014-02-12 14:28:14
【问题描述】:
我遇到了非常奇怪的情况...我正在尝试通过调用 drawViewHierarchyInRect: afterScreenUpdates: 从滚动视图(contentSize 超出屏幕边界三倍)捕获内容,如下所示:
+ (UIImage *) imageFromScrollView: (UIScrollView *) scrollView {
UIGraphicsBeginImageContext(size);
[view drawViewHierarchyInRect: CGRectMake(0, 0, scrollView.contentSize.width, scrollView.contentSize.height)
afterScreenUpdates: YES];
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
它适用于:iPhone 设备、iPhone 和 iPad 模拟器,但不适用于 iPad 设备。你有过类似的问题吗?我将不胜感激!
【问题讨论】:
-
你试过[view.layer renderInContext:UIGraphicsGetCurrentContext()];看看你是否得到任何不同的结果?此外,它不应该使图像完全变黑,但另一件事是你不应该真正使用 UIGraphicsBeginImageContext()。而是使用 UIGraphicsBeginImageContextWithOptions()。这样它就可以在视网膜/非视网膜设备上正确显示。
-
我也试过
UIGraphicsGetCurrentContext()和UIGraphicsBeginImageContext()。之前我用renderInContext:你提到的方法,但是我想利用iOS 7的新方法,这似乎更快。
标签: ios iphone objective-c ipad ios7