gpt4 book ai didi

ios - 渲染 PDF iOS-iPad-Quartz 时出现问题

转载 作者:行者123 更新时间:2023-11-29 13:49:36 25 4
gpt4 key购买 nike

我在将 pdf 渲染到 UIScroolView 时遇到问题。当我以横向模式启动我的应用程序时,pdf 会填充到 View 宽度边界,但不会填充到 View 高度边界。 pdf 内容进入屏幕但出现 UIScroolView 栏并且在 pdf 内容下我有一个白色区域。但是当我以纵向模式启动我的应用程序时,我没有任何问题,因为 pdf 已填充到 View 边界(宽度和高度)。

scroolView 具有以下属性:

theScrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
theScrollView.contentSize = self.view.bounds.size;

渲染pdf的方法是这样的:

- (void)drawLayer:(CATiledLayer *)layer inContext:(CGContextRef)context{

CGPDFPageRef drawPDFPageRef = NULL;
CGPDFDocumentRef drawPDFDocRef = NULL;

@synchronized(self) // Briefly block main thread
{
drawPDFDocRef = CGPDFDocumentRetain(_PDFDocRef);
drawPDFPageRef = CGPDFPageRetain(_PDFPageRef);
}

CGContextSetRGBFillColor(context, 1.0f, 1.0f, 1.0f, 1.0f);
CGContextFillRect(context, CGContextGetClipBoundingBox(context));

if (drawPDFPageRef != NULL) // Render the page into the context
{
NSLog(@"DRAW LAYER: drawPDFPageRef != NULL ");

CGFloat boundsHeight = self.bounds.size.height;

if (CGPDFPageGetRotationAngle(drawPDFPageRef) == 0)
{
NSLog(@"DRAW LAYER: CGPDFPageGetRotationAngle(drawPDFPageRef) == 0");
CGFloat boundsWidth = self.bounds.size.width;

CGRect cropBoxRect = CGPDFPageGetBoxRect(drawPDFPageRef, kCGPDFCropBox);
CGRect mediaBoxRect = CGPDFPageGetBoxRect(drawPDFPageRef, kCGPDFMediaBox);
CGRect effectiveRect = CGRectIntersection(cropBoxRect, mediaBoxRect);

CGFloat effectiveWidth = effectiveRect.size.width;
CGFloat effectiveHeight = effectiveRect.size.height;

CGFloat widthScale = (boundsWidth / effectiveWidth);
CGFloat heightScale = (boundsHeight / effectiveHeight);

CGFloat scale = (widthScale < heightScale) ? widthScale : heightScale;

CGFloat x_offset = ((boundsWidth - (effectiveWidth * scale)) / 2.0f);
CGFloat y_offset = ((boundsHeight - (effectiveHeight * scale)) / 2.0f);

y_offset = (boundsHeight - y_offset); // Co-ordinate system adjust

CGFloat x_translate = (x_offset - effectiveRect.origin.x);
CGFloat y_translate = (y_offset + effectiveRect.origin.y);

CGContextTranslateCTM(context, x_translate, y_translate);

CGContextScaleCTM(context, scale, -scale); // Mirror Y
}
else // Use CGPDFPageGetDrawingTransform for pages with rotation (AKA kludge)
{
NSLog(@"DRAW LAYER ELSE : CGPDFPageGetRotationAngle(drawPDFPageRef) == 0");

CGContextTranslateCTM(context, 0.0f, boundsHeight);
CGContextScaleCTM(context, 1.0f, -1.0f);

CGContextConcatCTM(context, CGPDFPageGetDrawingTransform(drawPDFPageRef, kCGPDFCropBox, self.bounds, 0, true));
}

CGContextDrawPDFPage(context, drawPDFPageRef);
}

CGPDFPageRelease(drawPDFPageRef); // Cleanup
CGPDFDocumentRelease(drawPDFDocRef);}

非常感谢!!

最佳答案

我已经通过添加解决了我的问题

theScrollView.contentSize= self.view.bounds.size

在 DidRotateFromInterfaceOrientation 中

关于ios - 渲染 PDF iOS-iPad-Quartz 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5596549/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com