Ver*_*sen 5 graphics ipad ios7
根据我的阅读,iOS7的新drawViewHierarchyInRect应该比CALayer的renderInContext更快.根据这个和这个,它应该是一个简单的问题:
[myView drawViewHierarchyInRect:myView.frame afterScreenUpdates:YES];
Run Code Online (Sandbox Code Playgroud)
代替
[myView.layer renderInContext:UIGraphicsGetCurrentContext()];
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试这个时,我只是得到空白的图像.执行捕获的完整代码,其中"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
Run Code Online (Sandbox Code Playgroud)
和contentImageView是一个UIImageView,在初始化期间作为子视图添加到self.
此外,我想要在图像中捕获的图形包含在其他子视图中,这些子视图在初始化期间也作为子视图添加到self(包括contentImageView).
使用drawViewHierarchyInRect时为什么会失败的任何想法?
*更新*
如果我绘制特定的子视图,我会得到一个图像,例如:
[contentImageView drawViewHierarchyInRect:contentImageView.frame afterScreenUpdates:YES];
Run Code Online (Sandbox Code Playgroud)
要么
[self.curvesView drawViewHierarchyInRect:self.curvesView.frame afterScreenUpdates:YES];
Run Code Online (Sandbox Code Playgroud)
但是我需要将所有可见的子视图合并为一个图像.
归档时间: |
|
查看次数: |
7243 次 |
最近记录: |