私がやろうとしているのは、webview のコンテンツが変更/ロードされるたびに UIWebView を UIImage に変換することです。
コードは次のとおりです。
- (void)viewDidLoad {
[self.tmpWebView loadHTMLString:[NSString stringWithFormat:@"Some %i HTML", 0,baseURL:nil];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
if (webView==tmpWebView && pngCount<[self.arrayOfHtmlContent count]) {
UIGraphicsBeginImageContext(webView.frame.size);
{
[webView.layer renderInContext: UIGraphicsGetCurrentContext()];
UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = CGRectMake(10, 10+((pngCount==1)?0:(pngCount-1)*100), 400, 200);
[imageView setBackgroundColor:[UIColor redColor]];
[_someScrollView addSubview:imageView];
//NSString *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat: @"Documents/Test-%i.png",pngCount]];
//[UIImagePNGRepresentation(image) writeToFile:pngPath atomically:YES];
}
UIGraphicsEndImageContext();
[self performSelector:@selector(loadWebViewWith:) withObject:[[NSArray alloc] initWithObjects:webView, [[NSNumber alloc] initWithInt:pngCount], nil ] afterDelay:0.3];//DELAY INCREASING DOES NOT CHANGE ANYTHING
pngCount++;
//NSLog(@"Finish%i: %@",(pngCount-1),[webView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML"]);
}
}
- (void) loadWebViewWith:(NSArray*)array {
[(UIWebView*)[array objectAtIndex:0] loadHTMLString:[NSString stringWithFormat:@"Another %i HTML", [[array objectAtIndex:1] intValue]] baseURL:nil];
}
理由はわかりませんが、作成された UIImage の一部が重複しています。UIImageへの変換が完了していないスレッドが原因である可能性がありますが、webviewの新しいコンテンツのロードを開始するための遅延(5秒に設定しても)は何も変わりません。
重複したUIImageを取得する理由を誰かに説明できますか?