2
我正在使用UIGraphicsBeginPDFContextToData创建带有多页的PDF文件。一切工作正常...我的问题是,当应用程序创建一个更大的页面数量,1 PDF,其冻结一小段时间,我无法控制用户界面。 PDF文件创建正确,但我想显示加载屏幕或类似的东西。我在UIActivityIndicator内测试的所有内容都像UIAlertView,或者工具栏中的UIActivityIndicator在PDF完成后显示。iPad使用加载动画创建PDF
这里是我创建NSData对象的方法。 NSLog显示正确的输出: 我真的不知道如何显示创建PDF的进度。显示当前页面的简单UILabel就是我所需要的。
- (NSData *)createPDFData:(int)type {
NSLog(@"START");
NSMutableData *pdfData = [NSMutableData data];
UIGraphicsBeginPDFContextToData(pdfData, drawImage.bounds, nil);
if (type == 1) {
UIGraphicsBeginPDFPage();
if ([self loadPDFBackground]) [paperImage drawRect:paperImage.bounds];
[drawImage drawRect:drawImage.bounds];
} else if (type == 2) {
NSArray *images = [NSArray arrayWithArray:[self loadImagesForPDF]];
int imageCount = [images count];
for (int i=0; i<imageCount; i++) {
NSLog(@"%@", [NSString stringWithFormat:@"Page %i of %i", i+1, imageCount]);
drawImage.image = [images objectAtIndex:i];
UIGraphicsBeginPDFPage();
if ([self loadPDFBackground]) [paperImage drawRect:paperImage.bounds];
[drawImage drawRect:drawImage.bounds];
}
}
UIGraphicsEndPDFContext();
NSLog(@"END");
return pdfData;
}
完美!非常感谢。 – HMMurdoc 2011-05-02 13:32:18