【问题标题】:Capture an image from the presentationLayer of a view.layer从 view.layer 的presentationLayer 捕获图像
【发布时间】:2012-08-30 14:17:22
【问题描述】:

最近我尝试使用动画元素捕获 UIWebView 的屏幕截图。问题是它们出现在屏幕截图上的原始位置,就像没有动画一样。 我尝试使用以下代码来解决此问题:

CGRect screenRect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContext(self.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[[UIColor clearColor] set];
CGContextFillRect(context, screenRect);
[[self.layer presentationLayer] renderInContext:context];
UIImage *screenImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return screenImage;

但它使用 EXC_BAD_ACCESS 删除了我的应用程序。 一项小研究表明,这种行为是由于快速变化的presentationLayer造成的;所以当我尝试 renderInContext 时,它实际上并不存在,[self.layer presentationLayer] 现在返回另一个 CALayer 对象。

所以问题是如何从动画层的当前状态中获取图像,或者(这也可能是一种解决方案)如何阻止它在屏幕截图时更改presentationLayer?

[更新] 更有趣的是:presentationLayer 似乎是空的,因为它的内容是 nil,正如我在调试器中看到的那样......

【问题讨论】:

  • 您能否使用计时器来为您的对象设置动画并在您想要截屏时暂停它?只是一个想法
  • 我希望我能...但是动画是由 JavaScript 执行的,停止它们非常复杂。我试图完全禁用它们,但应用程序仍然掉线。

标签: objective-c ipad uiview screenshot calayer


【解决方案1】:

好的,问题出在 CSS 中:

-webkit-transform: perspective(100px) translate3d(200px, 100px, -50px) rotateY(15deg);

任何透视或rotateY/rotateX 都会杀死屏幕截图上元素的位置,取自view.layer renderInContext。所以没有办法捕捉网页上“真正的 3d”定位元素。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-06
    • 2010-12-21
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-23
    • 2016-08-29
    相关资源
    最近更新 更多