简体   繁体   English

iPhone保存多个视图截图

[英]iphone save multiple views screenshot

I have an UIImagePickerController to which I add some subviews that contain images. 我有一个UIImagePickerController,向其中添加了一些包含图像的子视图。 I need to save the whole content as an image, but fail to do this. 我需要将整个内容另存为图像,但无法执行此操作。

For saving the content of the context i use the following code 为了保存上下文的内容,我使用以下代码

UIGraphicsBeginImageContext(self.view.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

It works for the UIImagePickerController but if i add subviews it stops at the 它适用于UIImagePickerController,但是如果我添加子视图,它将停止在

[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];

line, without any error in the console, just quits the app. 行,在控制台中没有任何错误,只是退出了应用程序。

Thanks! 谢谢!

If you are trying to grab everything on the screen in your screen shot, I found this on stack overflow: 如果您尝试获取屏幕快照中屏幕上的所有内容,那么我会在堆栈溢出中找到以下内容:

UIWindow *screenWindow = [[UIApplication sharedApplication] keyWindow];

UIGraphicsBeginImageContext(screenWindow.frame.size);
[screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

It will grab everything on the window. 它将抓住窗口上的所有内容。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM