繁体   English   中英

iPhone保存多个视图截图

[英]iphone save multiple views screenshot

我有一个UIImagePickerController,向其中添加了一些包含图像的子视图。 我需要将整个内容另存为图像,但无法执行此操作。

为了保存上下文的内容,我使用以下代码

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

它适用于UIImagePickerController,但是如果我添加子视图,它将停止在

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

行,在控制台中没有任何错误,只是退出了应用程序。

谢谢!

如果您尝试获取屏幕快照中屏幕上的所有内容,那么我会在堆栈溢出中找到以下内容:

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

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

它将抓住窗口上的所有内容。

希望这可以帮助。

暂无
暂无

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

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