我有这个代码:

CGRect visibleRect;
visibleRect.origin = mainViewController.scrollView.contentOffset;
visibleRect.size = mainViewController.scrollView.bounds.size;

我想将内容存储在visibleRect中的UIImage中。那可能吗?

最佳答案

此代码可能有效:

UIGraphicsBeginImageContext(visibleRect.size);
CGContextTranslateCTM(UIGraphicsGetCurrentContext(), visibleRect.origin.x,
    visibleRect.origin.y);
[mainViewController.scrollView.layer
    renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

10-08 05:22