【发布时间】:2016-01-03 21:00:29
【问题描述】:
我这里有这段代码,它将我的 UIView 放入 PDF 中。我遇到的问题是我的视图是一个详细视图控制器并且是可滚动的,并且 PDF 只能获取当时详细视图控制器内部的内容而不是完整视图,如果我在详细视图中移动,它将捕获任何内容我在的部分,而不是完整的东西。我正在尝试做的事情可能吗?
- (IBAction)Share:(id)sender {
NSMutableData *pdfData = [NSMutableData data];
// Points the pdf converter to the mutable data object and to the UIView to be converted
UIGraphicsBeginPDFContextToData(pdfData, spreadSheet.bounds, nil);
UIGraphicsBeginPDFPage();
CGContextRef pdfContext = UIGraphicsGetCurrentContext();
// draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData
[spreadSheet.layer renderInContext:pdfContext];
// remove PDF rendering context
UIGraphicsEndPDFContext();
// Retrieves the document directories from the iOS device
NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
NSString* documentDirectory = [documentDirectories objectAtIndex:0];
NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:@"test.pdf"];
// instructs the mutable data object to write its context to a file on disk
[pdfData writeToFile:documentDirectoryFilename atomically:YES];
NSLog(@"documentDirectoryFileName: %@",documentDirectoryFilename);
UIActivityViewController * activityController = [[UIActivityViewController alloc] initWithActivityItems:@[pdfData] applicationActivities:nil];
UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:activityController];
[popup presentPopoverFromRect:CGRectMake(self.view.frame.size.width - 36, 60, 0, 0)inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
更新
我一直在为此苦苦挣扎,我无法将完整视图转换为 PDF,我也一直在考虑采用我的 NSMutableArray 和我的 NSArray(这是我的 UIView 中使用的数据)并尝试将其转换为 PDF,但这听起来非常耗时,除非有人知道如何做到这一点。我想我对我应该走哪条路线感到困惑。
【问题讨论】:
-
那么你想要的其实不是“完整的 UIView”,它是一个 UIView 在一堆不同状态下的编译?您在详细视图控制器中使用什么?哪个班?
-
您是否尝试过使用电子表格的内容大小而不是边界?
-
“电子表格”的层次结构是什么?如果它是表格视图或集合视图,则没有直接的方法可以做到这一点,因为不可见的单元格甚至还没有呈现。
-
@Aris 在 tableView 或 collection view 的情况下,您可以随时强制渲染所有单元格。
-
就像你可以彻底循环并调用 [self tableView: self.tableView cellForRowAtIndexPath: indexPath];
标签: ios objective-c pdf uiview