2010-12-22 46 views
2

我想將UIView層次結構呈現爲CGContext或最終呈現爲UIImage。某些子視圖具有3D變換,其中renderInContext:會隨着陰影和其他一些CALayer屬性而被忽略。如何使用CoreAnimation組合模型將UIView層次結構呈現爲CGContext

從CALayer.h:

/* 
* WARNING: currently this method does not implement the full 
* CoreAnimation composition model, use with caution. */ 

- (void)renderInContext:(CGContextRef)ctx; 

我對UIGraphicsBeginImageContext一個電話後嘗試了幾種變化。

[self drawRect:[self bounds]]; 
[self.layer.delegate drawLayer:self.layer inContext:UIGraphicsGetCurrentContext()]; 
[self.layer renderInContext:UIGraphicsGetCurrentContext()]; 
[self.layer display]; 

充其量視圖層次結構呈現沒有3D變換。在最壞的情況下,圖像是空的。我想最終在圖像中使用有效的Alpha通道,因此屏幕截圖不太適用。

有沒有辦法呈現一個UIView層次結構,同時保留所有轉換和圖層屬性?

如果解決方案涉及遞歸迭代視圖層次,渲染每個視圖作爲圖像分開,以及將所有變換和屬性在每個父視圖的組合物的步驟,如何應用3D轉換?

+0

你有沒有得到這個問題的地方? – kevboh 2011-06-20 02:15:20

回答

0

我很抱歉,但沒有辦法如何做到這一點。

圖層的當前動畫狀態是私有的,無法訪問。 這可能是由於性能原因。啓用訪問動畫屬性的立即值,並具有與核芯顯卡兼容結構的值會降低顯卡的性能。