1
使用以下代碼,ctx未正確創建。它仍然nil
:CGPDFContextCreateWithURL未正確創建上下文
#import <QuartzCore/QuartzCore.h>
@implementation UIView(PDFWritingAdditions)
- (void)renderInPDFFile:(NSString*)path
{
CGRect mediaBox = self.bounds;
CGContextRef ctx = CGPDFContextCreateWithURL((CFURLRef)[NSURL URLWithString:path], &mediaBox, NULL);
CGPDFContextBeginPage(ctx, NULL);
CGContextScaleCTM(ctx, 1, -1);
CGContextTranslateCTM(ctx, 0, -mediaBox.size.height);
[self.layer renderInContext:ctx];
CGPDFContextEndPage(ctx);
CFRelease(ctx);
}
@end
在它顯示控制檯: <Error>: CGPDFContextCreate: failed to create PDF context delegate.
我試過幾個不同的路徑,所以我相當肯定是沒有問題的。感謝您的任何建議!