我有第一個視圖firstView
,也畫第二個視圖secondView
並將其作爲子視圖添加到firstView
。 我也有從firstView
PDF文件創建方法:從兩個視圖中繪製PDF
-(void)createPDFfromUIView:(UIView*)firstView
{
NSMutableData *pdfData = [NSMutableData data];
UIGraphicsBeginPDFContextToData(pdfData, self.view.bounds, nil);
UIGraphicsBeginPDFPage();
CGContextRef pdfContext = UIGraphicsGetCurrentContext();
[firstView.layer drawInContext:pdfContext];
UIGraphicsEndPDFContext();
NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
NSString* documentDirectory = [documentDirectories objectAtIndex:0];
NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:@"resolution.pdf"];
[pdfData writeToFile:documentDirectoryFilename atomically:YES];
NSLog(@"documentDirectoryFileName: %@",documentDirectoryFilename);
}
怎樣繪製一個PDF從這兩種觀點,所以PDF文件必須包含在一個頁面的firstView和secondView
新增
在的ViewController在loadView
方法
AWFirstView *firstView = [[AWFirstView alloc] init];
self.view = firstView;
self.secondView = [[AWSecondtView alloc] initWithFrame:CGRectMake(0, 50, 300., 300.)];
[self.secondView setBackgroundColor:[UIColor clearColor]];
self.createPDFButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.createPDFButton.frame =CGRectMake(0, 0, 88., 50.);
[self.createPDFButton setBackgroundColor:[UIColor whiteColor]];
[self.createPDFButton addTarget:self action:@selector(createPDF) forControlEvents:UIControlEventTouchUpInside];
[self updateView];
[self.view addSubview:self.drawWindow];
[self.view addSubview:self.createPDFButton];
在更新視圖是這樣的:
-(void)updateView
{
if(![self isViewLoaded])
return;
[[AWServices services].uiContext updateObjectInCurrentContext:&_resolution];
AWFirstView *view = (AWFirstView *)self.view;
view.post = _resolution.contact.officialPersonPost;
view.name = _resolution.contact.officialPersonFullname;
[view.superview setNeedsDisplay];
在
-(void)createPDF{
[self createPDFfromUIView:self.view];
}
它只保存firstView – dav
如果secondView是firstView的子視圖,它也應該保存在同一PDF中。你能告訴你如何創建firstView,secondView以及如何讓後者成爲前者的子視圖? – sergio
增加了更多代碼 – dav