0

I would like that my uiwebview change gif image when orientation changes so initially i'm using the following code to load the first image :

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

and i put the following code in orientationChanged function:

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

So the image work fine at first display and when i rotate the device, the (landscape or portrait) the image appear but a part of it was truncated.(after each rotation a part of image is ignored.....), any idea?

Thanks for help

Sultana
  • 153
  • 1
  • 1
  • 7

2 Answers2

0

That's because when you its loading the nib file as indicated in the xib file the uiimageview is most probably put at the end, so I guess you need to modify the frame coordinates in order to show the who image. if you want to test this theory, try to put in the xib file at the end of the image a button and run the application and rotate the device to show in lanscape, if my theory was correct the button won't show. I hope this helps! good luck!

coder
  • 5,200
  • 3
  • 20
  • 45
0

It's all about the orieitation issue,i guess so. here you should do thing like

1)whenever orientation chnages get that point and recognise the orientation suppose you got portrait then call your method which do the setUp of setting new image for portrait mode and do same vice versa.

Here is my logic just see it Carefully.

Below Method Called Whenever the Orientation gets Chnaged.Here You just need To allow To Chnage tHe orientation as you asked you need to set the Image for Landscape too.

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

}

Note:Here I am just Posting this Answer Only For Your Current REq i don't know how u r managing the Orientation ...

I hope it may helps you.

Kamar Shad
  • 6,089
  • 1
  • 29
  • 56
  • Thanks for your answer,i have tried this but willAnimateRotationToInterfaceOrientation was never called – Sultana Nov 13 '12 at 15:02
  • @Sultana That's Thing,i have told above in my Answer,in this case how can you set Image .it means you have to take care orientation also here it is the link for managing orientation in iOS6..,i think your app running over the iOS6...http://stackoverflow.com/questions/12577879/shouldautorotatetointerfaceorientation-is-not-working-in-ios-6/12581799#12581799 – Kamar Shad Nov 13 '12 at 15:06
  • My orientation work fine because i tested that with a jpeg image in a uimageview and the view rotate without any problem, but when i want to display a gif in uiwebview, – Sultana Nov 19 '12 at 11:27
  • @Sultana i could not understand,what were you trying to say? – Kamar Shad Nov 19 '12 at 11:44
  • Sorry i didn't complete my answer, so i have replaced my uiwebview with imageView to test with a jpeg image,and when the device change orientation, the uimageview change it too (work correctly on ios6 ) but when i'm using the webview to display a gif, i rotate the device so the webview change orientation but the image inside was turncated, is that the stringByEvaluatingJavaScriptFromString function could be the cause of this problem? – Sultana Nov 19 '12 at 15:23
  • @just tell me whether you have performed the ZoomIN/OUt operation on that Image before Changing the Rotation of device?please reply fast So that i could help you. – Kamar Shad Nov 19 '12 at 15:33
  • @Sultana can we come on chat ...http://chat.stackoverflow.com/rooms/19493/dissmissgroup11222 – Kamar Shad Nov 19 '12 at 17:00