我想实现的是拍摄未添加为子视图的UIView
的图像,然后将图像添加到视图中,然后将视图添加到视图层次。渲染不在视图层次结构中的UIView图层
我已经搜索,现在试了一会儿,并相信,这是根本不可能的。
显然的问题是,该观点尚未拟定(称为drawRect:
我猜的),如果它没有被添加作为一个子视图。 其实我认为renderInContext:
会自己调用drawRect/layer
。
将它作为子视图添加到imageContext之前是不够的,因为它不会立即呈现。
我采取的截图与renderInContext:
与视图层,看到这里我的代码:
[self.view addSubView:view];
UIGraphicsBeginImageContextWithOptions(view.frame.size, YES, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, -frame.origin.x, -frame.origin.y);
[view.layer renderInContext:context];
UIImage *renderedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
所以我的问题是,已经有人成功地呈现不可见UIView
如果怎么样?
可悲的不是我想要的。即使它能工作,我也不能在之前添加视图。 – yinkou