Google 및 So와 http://developer.apple.com/library/ios/#documentation/2ddrawing/conceptual/drawingprintingios/GeneratingPDF/GeneratingPDF.html에 대한 연구에도 불구하고. 나는 여전히 내 애플 리케이션이 문제에 대한 답변을 찾을 수 없습니다. 내 앱은보기가로드되는 즉시 웹보기로 그려진 PDF를 생성합니다. 문제는 메모리 경고 및 충돌이 발생하기 전에 iPhone 4, iPhone 5에서 약 8 페이지 만 생성 할 수 있다는 것입니다. 등PDF 메모리 경고/충돌
ICPDFEICRInspection1
2,3,4은 xibs는 앱이 모든 페이지를 생성 한 후 webView
에 전체 문서를 표시하는 순간 웹보기
로 유입되고/대형 도면이다.
내 질문 :가 어떻게 한 번에 그것을 한 페이지를 그리기 콘텐츠를 통해 반복,이 때문에 메신저는 사용자가 스크롤로 한 번에 한 페이지를 그리기보다는 메모리에 먼저 모두를로드 변경할 수 있습니다
- (void)viewWillAppear:(BOOL)animated
{
LogCmd();
[super viewWillAppear:animated];
if (self.pdfData != nil && self.viewHasUnloaded == YES) {
self.viewHasUnloaded = NO;
[self.webView loadData:self.pdfData MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:nil];
}
}
- (void)viewDidAppear:(BOOL)animated
{
LogCmd();
[super viewDidAppear:animated];
if (self.pdfData == nil) {
// Generate PDF
[ICUtils showProgressViewWithTitle:@"Generating PDF. This may take a minute..."];
[self performSelectorInBackground:@selector(generatePdf) withObject:nil];
}
}
- (void)generatePdf
{
NSMutableArray *pagesArray = [NSMutableArray array];
if ([self.certificate.certificateType.title isEqualToString:@"EICR"]) {
[pagesArray addObject:[[ICPDFEICRPage1 alloc] initWithCertificate:self.certificate]];
[pagesArray addObject:[[ICPDFEICRPage2 alloc] initWithCertificate:self.certificate]];
[self addObservationsToPagesArray:pagesArray];
[self addDistributionBoardsToPagesArray:pagesArray];
[pagesArray addObject:[[ICPDFEICRInspection alloc] initWithCertificate:self.certificate]];
[pagesArray addObject:[[ICPDFEICRInspectionPage1 alloc] initWithCertificate:self.certificate]];
[pagesArray addObject:[[ICPDFEICRInspectionPage2 alloc] initWithCertificate:self.certificate]];
[pagesArray addObject:[[ICPDFEICRInspectionPage3 alloc] initWithCertificate:self.certificate]];
[pagesArray addObject:[[ICPDFEICRPageFinal alloc] initWithCertificate:self.certificate]];
}
// Set page count on all pages
int pageNumber = 0;
for (ICCertificateComponent *page in pagesArray) {
page.pageNumber.text = [NSString stringWithFormat:@"%d", ++pageNumber];
page.pageCount.text = [NSString stringWithFormat:@"%d", pagesArray.count];
}
NSData *pdfData = [self createPdfWithPages:pagesArray];
[self performSelectorOnMainThread:@selector(pdfDone:) withObject:pdfData waitUntilDone:YES];
}
}
- (void)pdfDone:(NSData *)data
{
self.pdfData = data;
[self.webView loadData:self.pdfData MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:nil];
[ICUtils removeProgressView];
}
- (NSData *)createPdfWithPages:(NSArray *)pages
{
// Creates a mutable data object for updating with binary data, like a byte array
NSMutableData *pdfData = [NSMutableData data];
ICCertificateComponent *firstPage = [pages objectAtIndex:0];
UIGraphicsBeginPDFContextToData(pdfData, firstPage.contentView.bounds, nil);
for (int i = 0; i < pages.count; i++) {
ICCertificateComponent *thisPage = [pages objectAtIndex:i];
UIGraphicsBeginPDFPageWithInfo(thisPage.contentView.bounds, nil);
CGContextRef pdfContext = UIGraphicsGetCurrentContext();
[thisPage.contentView.layer renderInContext:pdfContext];
}
UIGraphicsEndPDFContext();
return pdfData;
}
감사 마이크, 필자는이 조언/정교 대해 이동하는 방법을 잘 크게 – JSA986