1

私はiPhoneの開発に不慣れです。私のアプリでは、多数のviewController、Webビュー、ツールバー、タブバーなどを使用しています。ここでは、すべてのWebビューで、対応するデバイスビューの向き(縦向きまたは横向き、あるいはその逆)を実現したいと考えています。これらのWebビューがタブバーコントローラーWebビューの下にあることを除いてすべてのWebビューで方向付けを行うことができました(タブバービューコントローラーまたはタブバーコントローラービューのサブビューのいずれかである可能性があります)。

ここでは、以下のコードを使用してWebビューを追加します。

  contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
  contentView.autoresizingMask = (UIViewAutoresizingFlexibleWidth |                  UIViewAutoresizingFlexibleHeight);
  self.view = contentView;
  self.view.autoresizesSubviews = YES;


  CGRect webFrame = [[UIScreen mainScreen] applicationFrame];
  webFrame.origin.y -= 20.0;

  webView1 = [[UIWebView alloc] initWithFrame:webFrame];

  [contentView addSubview:webView1]; 

オリエンテーションを達成するために以下の方法を使用して、

- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) orientation 
 {

  return YES;
 }


 - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
     {
           if(fromInterfaceOrientation == UIInterfaceOrientationPortrait){
           [webView1 stringByEvaluatingJavaScriptFromString:@"rotate(0)"];

     }

そうしないと {

   [webView1 stringByEvaluatingJavaScriptFromString:@"rotate(1)"];
 }

}

誰でも解決してください!

4

1 に答える 1

2

さて、これを試してみましょう:

ステップ1:TabBarControllerクラスのカスタムクラスを次のように作成します。

@interface CustomTabBarController : UITabBarController {

}

@end

In CustomTabBarController.m write

`#import "CustomTabBarController.h"

@implementation CustomTabBarController

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{

    // Always returning YES means the view will rotate to accomodate any orientation.

    return YES;

}

@end

ステップ2:appDelegateで次のように記述します。

UITabBarController "CustomTabBarController"を変更し、InterfaceBuilderのクラス参照をCustomTabBarControllerに変更します

于 2010-07-22T11:11:09.060 に答える