我使用下面的代码拍摄视图的快照。它适用于大多数情况,但不适用于包含UIDatePicker的视图。
UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *snapshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
观点是:
它生成的图像看起来很奇怪:
任何人都可以告诉我为什么会发生这种情况,以及如何拍摄视图的快照包含UIDatePicker
。
提前致谢。
答案 0 :(得分:1)
不使用图层的renderInContext方法,而是使用:
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];
答案 1 :(得分:0)
在调用UIGraphicsBeginImageContextWithOptions
()