4

我正在将 PDF 页面绘制到 CGContext 中。

为了正确绘制它,我对上下文应用了一些转换。

呈现为 rect 的 pdf 页面小于视图的 rect。

我想创建第三个视图,它与渲染 pdf 的视图部分具有完全相同的框架。

我的解决方案有效,但并非完全有效。有时(很多时候)矩形是错误的。

这就是我正在做的事情:

- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)context {
      CGContextSaveGState(context);
      // apply transforms to context
      // draw pdf page

      CGRect calculatedFromRect = CGRectApplyAffineTransform(pageRect, CGContextGetCTM(context));
      CGContextRestoreGState(context);

      // now draw a green rect to test the frame on a not transformed context
      GContextSetFillColorWithColor(context, [UIColor greenColor].CGColor);
      CGContextFillRect(context, calculatedFromRect);

      self.thirdView.frame = calculatedFromRect;
 }

第三个视图是红色的。当两个矩形(视图和绘图)相等时,我在屏幕上看到一个棕色矩形(绿色矩形顶部带有 alpha 的红色)。但有时我可以看到它们两个彼此分开(偏移量和大小差异......当这种情况发生时,thirdView.frame 比 calcularedRect 大)。

由于所有涉及的视图都具有相同的大小和坐标,因此不使用 convertRect:fromView: 转换坐标应该不是问题。但我试过了,结果是一样的。

4

0 回答 0