拍摄快照的视图包含UIDatePicker
问题描述:
我使用下面的代码拍摄一个视图的快照。它适用于大多数情况,但不适用于包含UIDatePicker的视图。拍摄快照的视图包含UIDatePicker
UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *snapshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
的观点是:
它生成的图像看起来奇怪:
谁能告诉我,为什么发生这种情况以及如何采取的快照视图包含UIDatePicker
。
在此先感谢。
答
而不是使用层的renderInContext方法,使用:
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];
+0
谢谢你。对不起,接受答案已经太晚了。它适用于iOS7和iOS9,我没有在两个系统版本上测试过其他设备。 – KudoCC 2016-06-24 02:23:28
你解决这个问题? – demon9733 2015-09-23 10:03:21
你解决了这个问题吗? – 2016-06-23 20:25:45
@ demon9733 user1390486的回答是有效的。 – KudoCC 2016-06-24 02:22:12