2012-11-13 30 views
0

我想,当方向改变所以最初 我使用下面的代码我UIWebView的变化gif图片加载第一图像:UIWebView的变化图像时方向改变

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]; 

因此,在第一显示图像的工作细,当我旋转设备中,(横向或纵向)上的图像出现,但它的一部分被截断(后每转动一圈的一部分。图像被忽略.....),a你有想法吗?

感谢您的帮助

回答

0

这是因为当你它的加载笔尖文件作为厦门国际银行文件的UIImageView是最有可能把在末端,所以我想你需要修改帧坐标,以示谁的形象。如果你想测试这个理论,试着在图像末尾的xib文件中放一个按钮,然后运行应用程序并旋转设备以在lanscape中显示,如果我的理论是正确的,那么按钮将不会显示。 我希望这有助于!祝你好运!

0

这是所有关于orieitation的问题,我想是的。 这里你应该做的事情一样

1)每当方向chnages得到这一点,并承认方位 假设你有肖像,然后打电话给你的方法,做人像模式设定新形象的建立和做同样的,反之亦然。

这里是我的逻辑只是看到它仔细。

下面的方法调用每当方向变得Chnaged.Here你只需要允许To Chnage方向,因为你问你需要设置景观图像也。

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    if(toInterfaceOrientation ==UIInterfaceOrientationPortrait||toInterfaceOrientation==UIInterfaceOrientationMaskPortraitUpsideDown); 
    { 
     [self setImagesForPortraitView]; 
    } 
else 
    { 
     [self setImagesForLandscapeView]; 
    } 

    //setImagesForPortraitView and setImagesForLandscapeView would be your custom method which setUP the Images for different orientation 
//So here as Orientation chnages you can easily set the new image to Webview as you said. 

}

注:在这里,我只是张贴这答案仅对当前REQ我不知道乌尔管理方向...

我希望它可以如何帮助您。

+0

感谢您的回答,我已经尝试过,但willAnimateRotationToInterfaceOrientation从来没有被称为 – Sultana

+0

@Sultana这就是事情,我已经在上面告诉我的答案,在这种情况下,你如何设置图像。这意味着你必须照顾方向也在这里这是在iOS6中管理方向的链接..,我认为你的应用程序运行在iOS6上... http://stackoverflow.com/questions/12577879/shouldautorotatetointerfaceorientation-is-not-working-in-ios-6/12581799 #12581799 – Kamarshad

+0

我的方向工作正常,因为我测试了一个uimageview中的jpeg图像和视图没有任何问题旋转,但是当我想在uiwebview中显示一个gif时, – Sultana