OGeek|极客世界-中国程序员成长平台

标题: ios - 截取 UIPickerView 的屏幕截图 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 06:58
标题: ios - 截取 UIPickerView 的屏幕截图

我使用以下代码截取我的 View :

UIGraphicsBeginImageContextWithOptions(containerView.bounds.size, NO, [[UIScreen mainScreen] scale]);
[toController.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

它适用于大多数情况,但当 View 包含 UIPickerView

时会生成下图

image that is produced

这就是我想要制作的图像。

the desired image

发生了什么,我该如何解决这个问题,有什么想法吗??

谢谢大家!

编辑:请注意这发生在设备和模拟器上



Best Answer-推荐答案


我通过使用 drawViewHierarchyInRect:

解决了这个问题
UIGraphicsBeginImageContextWithOptions(containerView.bounds.size, NO, [[UIScreen mainScreen] scale]);
[toController.view drawViewHierarchyInRect:containerView.bounds afterScreenUpdates:YES];
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

关于ios - 截取 UIPickerView 的屏幕截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30055107/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4