向きが変わったときに uiwebview の gif 画像を変更したいので、最初は次のコードを使用して最初の画像を読み込みます。
NSString * url = @"gif image url...";
int width = width of image;
int height = height of image;
NSString * htmlCode = [NSString stringWithFormat:@"<html><head><body leftmargin=\"0\" topmargin=\"0\"><img id=\"gifimg\" src=\"%@\" width=\"%i\" height=\"%i\"></body></html>", url, width,height];
[tmpWebView loadHTMLString:htmlCode baseURL:nil];
そして、次のコードをorientationChanged関数に入れました:
NSString url = @"portrait image url...";
int width = width of portrait image;
int height = height of portrait image;
if (deviceOrientation == UIInterfaceOrientationLandscapeLeft) {
url = @"landscape image url...";
width = width of landscape image;
height = height of landscape image;
}
NSString * jsString = [[NSString alloc] initWithFormat:@"document.getElementsByTagName('img')[0].style.width= '%dpx';document.getElementsByTagName('img')[0].style.height= '%dpx';document.getElementsByTagName('img')[0].src= '%@'", width,height, url];
[webview stringByEvaluatingJavaScriptFromString:jsString];
[jsString release];
[webview setBackgroundColor:[UIColor clearColor]];
[webview setOpaque:NO];
そのため、画像は最初の表示で正常に機能し、デバイスを回転させると、(横向きまたは縦向き) 画像が表示されますが、その一部が切り捨てられました (各回転の後、画像の一部は無視されます.....)、考え?
手伝ってくれてありがとう