簡體   English   中英

如何使用CALayer renderInContext並保持透視變換?

[英]How do I use CALayer renderInContext and keep the perspective transform?

如何使用CALayer renderInContext並保留圖層的透視變換(m34) 看起來這個方法假設一個Identity變換。 我已經嘗試過改變上下文這樣的事情,這對於平移,旋轉和縮放來說很好,但似乎沒有辦法保持3D變換的視角。

也許是提出這個問題的更好方法:如何在繪制CGContextRef時應用透視圖?

您可能希望查看方法drawViewHierarchyInRect:afterScreenUpdates:自iOS 7.0以來提供的方法。 將該方法應用於包含CALayers的視圖將保持其3D變換。

示例代碼:

BOOL opaqueBackground = YES;
UIGraphicsBeginImageContextWithOptions(theViewContainingYourCALayers.bounds.size, !opaqueBackground, 0);
[theViewContainingYourCALayers drawViewHierarchyInRect:theViewContainingYourCALayers.bounds afterScreenUpdates:YES];
[UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

正如matt指出的那樣,僅僅依賴於renderInContext:是不可能的,因為它忽略了仿射之外的任何轉換。

遲到的答案,但我希望它仍然有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM