0

向きが変わったときに 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];

そのため、画像は最初の表示で正常に機能し、デバイスを回転させると、(横向きまたは縦向き) 画像が表示されますが、その一部が切り捨てられました (各回転の後、画像の一部は無視されます.....)、考え?

手伝ってくれてありがとう

4

2 に答える 2

0

これは、xib ファイルに示されているように nib ファイルをロードすると、おそらく uiimageview が最後に配置されるため、who 画像を表示するにはフレーム座標を変更する必要があると思います。この理論をテストしたい場合は、xib ファイルの画像の最後にボタンを配置してアプリケーションを実行し、デバイスを回転させて風景で表示してみてください。私の理論が正しければ、ボタンは表示されません。これが役立つことを願っています!幸運を!

于 2012-11-13T13:41:53.047 に答える
0

それはすべて向きの問題に関するものです、私はそう思います。ここであなたは次のようなことをするべきです

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.

}

注:ここでは、現在のREqについてのみこの回答を投稿しています。オリエンテーションをどのように管理しているかわかりません...

お役に立てば幸いです。

于 2012-11-13T14:32:55.067 に答える