我試圖獲取另一個控制器視圖的快照以在動畫中使用。我使用下面的代碼,但我什麼也看不見,但這種觀點的背景顏色,並沒有其子視圖(兩個按鈕,一個文本視圖和標籤):視圖快照不渲染
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
FirstPageController *fpController = [self.storyboard instantiateViewControllerWithIdentifier:@"FirstPage"];
UIGraphicsBeginImageContext(fpController.view.bounds.size);
NSLog(@"%@",fpController.view.subviews);
[fpController.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGSize destinationSize = CGSizeMake(90, 122);
UIGraphicsBeginImageContext(destinationSize);
[viewImage drawInRect:CGRectMake(0,0,destinationSize.width,destinationSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.imageView2 = [[UIImageView alloc] initWithImage:newImage];
self.imageView2.center = self.view.center;
[self.view addSubview:self.imageView2];
NSLog(@"%@",NSStringFromCGSize(self.imageView2.image.size));
}
我記錄的所有相關的東西,fpController,imageView,圖像和所有正確記錄。
編輯完成後:如果我切換到當前控制器的視圖,它工作正常,所以我認爲這與獲取不在屏幕上的視圖的快照有關。可以這樣做嗎?
您是否嘗試過在上下文中渲染各個子視圖? –
不,從對類似問題的答案,因爲我的理解是,這將使所有子視圖 – rdelmar