Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UIWebView在方向更改时更改图像_Iphone_Objective C_Uiwebview_Orientation Changes - Fatal编程技术网

Iphone UIWebView在方向更改时更改图像

Iphone UIWebView在方向更改时更改图像,iphone,objective-c,uiwebview,orientation-changes,Iphone,Objective C,Uiwebview,Orientation Changes,我希望我的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\" topmar

我希望我的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];
因此,图像在第一次显示时工作正常,当我旋转设备时,图像(横向或纵向)会出现,但其中一部分被截断。(每次旋转后,图像的一部分被忽略…),你知道吗


感谢您的帮助

这是因为当您加载nib文件(如xib文件所示)时,uiimageview很可能放在末尾,因此我想您需要修改帧坐标以显示who图像。如果您想测试这一理论,请尝试在图像末尾的xib文件中放入一个按钮,然后运行应用程序并旋转设备以在lanscape中显示,如果我的理论正确,按钮将不会显示。
我希望这有帮助!祝你好运

我想这都是关于定位的问题。 在这里,你应该这样做

1) 无论何时,方向技术都会得到该点并识别方向 假设你得到了肖像,然后调用你的方法为肖像模式设置新图像,反之亦然

这是我的逻辑,请仔细看看

每当改变方向时,都会调用下面的方法。在这里,您只需允许按照要求改变方向,您还需要为横向设置图像。

 - (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.
}

注意:这里我只是发布这个答案只是为了你目前的要求,我不知道你是如何管理的方向


我希望它能对您有所帮助。

谢谢您的回答,我已经尝试过了,但WillAnimateRotationInterfaceOrientation从来都不是called@Sultana这就是我在上面的回答中提到的,在这种情况下,如何设置图像。这意味着你必须注意方向。在这里,这是iOS6中管理方向的链接。。,我认为你的应用程序运行在iOS6上…我的定向工作正常,因为我在uimageview中使用jpeg图像进行了测试,视图旋转没有任何问题,但是当我想在uiwebview中显示gif时,@Sultana我不明白,你想说什么?抱歉,我没有完成我的回答,因此,我将uiwebview替换为imageView以使用jpeg图像进行测试,当设备改变方向时,uimageview也会改变它(在ios6上正常工作),但当我使用webview显示gif时,我旋转设备以使webview改变方向,但内部的图像被旋转,stringByEvaluatingJavaScriptFromString函数可能是导致此问题的原因吗?
 - (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.