本文介绍了重复的CALayer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我想从UIView创建PDF。
现在我想复制该图层并将其调整为DIN A4页面大小。

I want to create a PDF from a UIView.Now I want to copy the layer and resize it to a DIN A4 page size.

CGRect A4PageRect = CGRectMake(0, 0, 595, 842);
CALayer *myLayer = [pdfView layer];
myLayer.bounds = pageRect;

但是此cody调整了屏幕上可见层的大小。

But this cody resizes the visible layer on my screen.

如何复制图层内容以调整其大小以适合A4页面?

How can I copy the layers contents to resize it to fit an A4 page?

感谢朱利安人的帮助

推荐答案

无法复制CALayer。

There is no way to duplicate a CALayer.

(对于CoreAnimation来说,以一种明智的方式来实现它是很困难的。可能会有一整层子层树,它们都可能有影响其行为的委托,

(It would be difficult for CoreAnimation to implement that in a sensible way. There might be a whole tree of sublayers, and they all might have delegates that influence their behavior, which wouldn't expect to suddenly get requests from the copies of the layers.)

我只能猜测找到一个更好的解决方案,因为我不了解您的确切情况。您是否有要调整大小的PDF,还是只想获取一个任意的现有图层并从中制作PDF文档?

I can only guess at a better solution, because I don't understand your exact situation. Do you have a PDF that you are trying to resize, or do you just want take an arbitrary existing layer and make a PDF document out of it?

如果是后者:


  1. 使用或创建PDF绘图上下文

  2. 调用或以创建页面

  3. 调用使用
  4. 缩放/Reference/CGContext/Reference/reference.html#//apple_ref/c/func/CGContextScaleCTM rel = nofollow> CGContextScaleCTM 因此您的图层将适合在PDF页面中

  5. 致电将图层绘制到PDF上下文中

  6. 致电 UIGraphicsEndPDFCo ntext 完成PDF

  1. Use UIGraphicsBeginPDFContextToData or UIGraphicsBeginPDFContextToFile to create a PDF drawing context
  2. Call UIGraphicsBeginPDFPage or UIGraphicsBeginPDFPageWithInfo to create a page
  3. Call UIGraphicsGetCurrentContext to get the PDF drawing context
  4. Scale using CGContextScaleCTM so your layer will fit in the PDF page
  5. Call -[CALayer renderInContext:] to draw the layer into the PDF context
  6. Call UIGraphicsEndPDFContext to finish the PDF

请注意,这看起来很糟糕。图层是基于位图的,因此您将在PDF中获得位图。另外,-[CALayer renderInContext:] 的渲染与屏幕上的渲染并不完全相同-请参阅文档中的注释。

Note that this may look terrible. Layers are bitmap-based, so you'll get a bitmap in your PDF. Also, -[CALayer renderInContext:] doesn't render exactly the same as it does on-screen -- see the note in the documentation.

如果出现问题,则需要添加一条绕过CALayer的单独绘制路径。在第5步中,您将使用CoreGraphics进行自己的绘制。

If this is a problem, you'll need to add a separate drawing path that bypasses CALayer. In step 5, you would do your own drawing using CoreGraphics.

这篇关于重复的CALayer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 17:38