Ipad iOS7&x27;s drawViewHierarchyInRect不';不行?

Ipad iOS7&x27;s drawViewHierarchyInRect不';不行?,ipad,graphics,ios7,Ipad,Graphics,Ios7,据我所知,iOS7的新版本应该比CALayer的更快。根据和,这应该是一个简单的问题: [myView drawViewHierarchyInRect:myView.frame afterScreenUpdates:YES]; 而不是 [myView.layer renderInContext:UIGraphicsGetCurrentContext()]; 然而,当我尝试这一点,我只是得到空白图像。执行捕获的完整代码,其中“self”是UIView的子类 // YES = o

据我所知,iOS7的新版本应该比CALayer的更快。根据和,这应该是一个简单的问题:

[myView drawViewHierarchyInRect:myView.frame afterScreenUpdates:YES];
而不是

[myView.layer renderInContext:UIGraphicsGetCurrentContext()];
然而,当我尝试这一点,我只是得到空白图像。执行捕获的完整代码,其中“self”是UIView的子类

        // YES = opaque. Ignores alpha channel, so less memory is used.
        // This method for some reasons renders the
    UIGraphicsBeginImageContextWithOptions(self.bounds.size, YES, self.window.screen.scale);    // Still slow.

    if ( [AIMAppDelegate isOniOS7OrNewer] )
        [self drawViewHierarchyInRect:self.frame afterScreenUpdates:YES]; // Doesn't work!
    else
        [self.layer renderInContext:UIGraphicsGetCurrentContext()];     // Works!

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    contentImageView.image = image; // this is empty if done using iOS7's way
contentImageView是一个UIImageView,在初始化期间作为子视图添加到self

此外,我希望在图像中捕获的图形包含在其他子视图中,这些子视图在初始化期间也作为子视图添加到self中(包括contentImageView)

你知道为什么使用drawViewHierarchyInRect会失败吗

*更新*

如果我绘制一个特定的子视图,我会得到一个图像,例如:

[contentImageView drawViewHierarchyInRect:contentImageView.frame afterScreenUpdates:YES];


但是,我需要将所有可见的子视图合并到一个图像中。

尝试使用
self.bounds
而不是
self.frame
-您可能会在创建的图像上下文的边界之外渲染视图的图像。

哈哈,通过实验,我刚刚发现了相同的结果。这就是问题所在!谢谢。唯一奇怪的是drawViewHierarchyInRect实际上比renderInContext慢一点。我觉得应该快一点?知道为什么没有吗?可能是
后屏幕更新:是的
-我相信这会迫使它等待下一次显示图层树。如果关闭该选项,速度是否会改变?在我的例子中,有时
drawViewHierarchyInRect:afterScreenUpdates:
返回否。我使用self.frame和self.bounds得到相同的结果。然而,正如上面@VernJensen所说,我的问题是通过使用
renderInContext
解决的。谢谢
[self.curvesView drawViewHierarchyInRect:self.curvesView.frame afterScreenUpdates:YES];