有很多关于如何将视图保存为图像的主题。所有人都给出了同样的答案:
CGRect rect = [myView bounds];
UIGraphicsBeginImageContextWithOptions(rect.size,YES,[[UIScreen mainScreen] scale]);
CGContextRef context = UIGraphicsGetCurrentContext();
[myView.layer renderInContext:context];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
我的问题是我的视图包含几个包含图像的连接imageView。我希望将“持有者”视图保存为与其中驻留的图像大小相对应的大小。因此,如果我有两张400x400并排的图像,我想保存400x800图像,不管它们显示的是30x60。
另外,上面的代码只捕获屏幕上显示的内容而忽略了其余部分。例如,如果我想要获得整个scrollview的内容大小,那是不可能的。
任何想法?