我正在从 UIScrollView 创建 pdf。
它工作正常并创建一个PDF,但问题是在创建pdf后scrollView从屏幕上消失了,当我再次加载应用程序然后它再次显示,所以我认为由于pdf创建它隐藏了任何方式来取消隐藏它之后创建 PDF。
我正在使用以下代码:
-(void)createPDFfromUIView: (UIView*)aView saveToDocumentsWithFileName: (NSString*)aFilename
{
NSMutableData *pdfData = [NSMutableData data];
CGRect scrollSize = CGRectMake(1018,76,1010,1600);
[scrollView setFrame:CGRectMake(1018,76,1010,1600)];
// Points the pdf converter to the mutable data object and to the UIView to be converted
UIGraphicsBeginPDFContextToData(pdfData,scrollView.bounds, nil);
UIGraphicsBeginPDFPage();
CGContextRef pdfContext = UIGraphicsGetCurrentContext();
// draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData
[aView.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:aFilename];
// instructs the mutable data object to write its context to a file on disk
[pdfData writeToFile:documentDirectoryFilename atomically:YES];
NSLog(@"documentDirectoryFileName: %@",documentDirectoryFilename);
}