在包含UIDatePicker的视图上拍摄快照

时间:2014-10-22 08:19:16

标签: ios

我使用下面的代码拍摄视图的快照。它适用于大多数情况,但不适用于包含UIDatePicker的视图。

    UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0.0);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *snapshot = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

观点是:

enter image description here

它生成的图像看起来很奇怪:

enter image description here

任何人都可以告诉我为什么会发生这种情况,以及如何拍摄视图的快照包含UIDatePicker

提前致谢。

2 个答案:

答案 0 :(得分:1)

不使用图层的renderInContext方法,而是使用:

[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];

答案 1 :(得分:0)

在调用UIGraphicsBeginImageContextWithOptions()

时设置opaque = NO