我使用下面的代碼來繪製和旋轉PDF文件。它與iOS 5.x完美無瑕,但在iOS 4.3下,只有一個白頁出現在調試器中的錯誤:iOS 4.3 PDF文件呈現問題
無效`Contents':不是一個數組流。
錯誤發生在「CGContextDrawPDFPage(context,pdfPage)」之後;
爲什麼它可以與iOS 5.x一起使用,但不是4.3.x?我嘗試了不同的PDF文件,但仍得到相同的結果。
我該如何解決這個問題?
pdfpage定義爲:
- (void)setPage:(CGPDFPageRef)newPage
{
CGPDFPageRelease(self->pdfPage);
self->pdfPage = CGPDFPageRetain(newPage);
}
在那裏發生的方法,包括:
-(void)drawLayer:(CALayer*)layer inContext:(CGContextRef)context
{
// First fill the background with white.
CGContextSetRGBFillColor(context, 1.0,1.0,1.0,1.0);
CGContextFillRect(context,self.bounds);
CGContextSaveGState(context);
int rotate = CGPDFPageGetRotationAngle(pdfPage);
switch (rotate) {
case 0:
CGContextTranslateCTM(context, 0.0, self.bounds.size.height);
CGContextScaleCTM(context, 1, -1);
break;
case 90:
CGContextScaleCTM(context, 1.0, -1.0);
CGContextRotateCTM(context, -M_PI/2);
break;
case 180:
case -180:
CGContextScaleCTM(context, 1, -1);
CGContextTranslateCTM(context, self.bounds.size.width, 0);
CGContextRotateCTM(context, M_PI);
break;
case 270:
case -90:
CGContextTranslateCTM(context, self.bounds.size.height, self.bounds.size.width);
CGContextRotateCTM(context, M_PI/2);
CGContextScaleCTM(context, -1, 1);
break;
}
CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
CGContextSetRenderingIntent(context, kCGRenderingIntentDefault);
CGContextScaleCTM(context, myScale,myScale);
CGContextDrawPDFPage(context, pdfPage); // the error shows up right after executing this line
CGContextRestoreGState(context);
}
什麼是'pdfPage'?檢查它是否正確初始化。 – 2012-03-31 07:35:03
請注意,向下/向上投票不幫助我解決問題! – 2012-03-31 07:36:21
@MitulNakum其初始化正確它與ios 5.x但不是ios 4.3.x我有更新代碼。感謝您試圖提供幫助。 – 2012-03-31 07:39:04