0

我正在从 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);
}
4

1 回答 1

0

据我所知,问题出在下面一行

[scrollView setFrame:CGRectMake(1018,76,1010,1600)];

这将使滚动视图超出可见区域,因为您的 Origin X 是 1018。因此,实际上它不是隐藏的,而是在屏幕或可见区域之外。

你真的需要那条线吗?

于 2013-05-20T05:01:13.383 回答