我希望我的 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];
所以图像在第一次显示时工作正常,当我旋转设备时,(横向或纵向)图像出现但其中一部分被截断。(每次旋转后,图像的一部分被忽略.....),任何主意?
感谢帮助