2011-01-12 14 views
3

問題: ルートView Controllerに2台のView Controllerがロードされています。どちらのサブビューレイアウトも向きの変更に対応します。 [UIView transformationFromView:...]を使用して2つのビューを切り替える。どちらのサブビューは、以前に隠されたビューが深刻なレイアウトを持って自分でうまく動作しますが、非表示のUIViewオリエンテーションの変更/レイアウトの問題

  1. ビューが交換されている...場合
  2. オリエンテーションは
  3. ビューが再び

を交換され変更します問題。これらのステップを繰り返すほど、問題が悪化します。

実装の詳細

私は3 viewsControllersを持っています。

  1. MyAppViewController
  2. A_ViewController
  3. B_ViewController

& B ViewControllers各背景画像を有し、のUIWebViewとAQGridViewそれぞれ。あなたに私はそれをすべてを設定してい方法の例を与えるために、ここでは簡潔にするため

- (void)loadView { 

    [super loadView]; 

    // background image 
    // Should fill the screen and resize on orientation changes 
    UIImageView *bg = [[UIImageView alloc] initWithFrame:self.view.bounds]; 
    bg.contentMode = UIViewContentModeCenter; 
    bg.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; 
    bg.image = [UIImage imageNamed:@"fuzzyhalo.png"]; 
    [self.view addSubview:bg]; 

    // frame for webView 
    // Should have a margin of 34 on all sides and resize on orientation changes 
    CGRect webFrame = self.view.bounds; 
    webFrame.origin.x = 34; 
    webFrame.origin.y = 34; 
    webFrame.size.width = webFrame.size.width - 68; 
    webFrame.size.height = webFrame.size.height - 68; 

    projectView = [[UIWebView alloc] initWithFrame:webFrame]; 
    projectView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; 

    [self.view addSubview:projectView]; 

} 

... A_ViewControllerためのloadViewメソッドだ、B_ViewControllerでAQGridViewはほとんど同じように設定されています。

これら両方のビューは、単独で問題なく動作します。しかし、私は...このようAppViewControllerでそれらの両方を使用

- (void)loadView { 

     [super loadView]; 

     self.view.autoresizesSubviews = YES; 
     [self setWantsFullScreenLayout:YES]; 

     webView = [[WebProjectViewController alloc] init]; 
     [self.view addSubview:webView.view]; 

     mainMenu = [[GridViewController alloc] init]; 
     [self.view addSubview:mainMenu.view]; 

     activeView = mainMenu; 

     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(switchViews:) name:SWAPVIEWS object:nil]; 


    } 

と私はを通じて自分の道を手探りしています。この

- (void) switchViews:(NSNotification*)aNotification; 
{ 
    NSString *type = [aNotification object]; 

    if ([type isEqualToString:MAINMENU]){ 
     [UIView transitionFromView:activeView.view toView:mainMenu.view duration:0.75 options:UIViewAnimationOptionTransitionFlipFromRight completion:nil]; 
     activeView = mainMenu; 
    } 

    if ([type isEqualToString:WEBVIEW]) { 
     [UIView transitionFromView:activeView.view toView:webView.view duration:0.75 options:UIViewAnimationOptionTransitionFlipFromLeft completion:nil]; 
     activeView = webView; 
    } 

    // These don't seem to do anything 
    //[mainMenu.view setNeedsLayout]; 
    //[webView.view setNeedsLayout]; 

} 

ように私自身のSwitchViewメソッドを使用して、2つのビューbetweem切り替えますこれは私がやったことの多くが間違って実装されていると思われますので、別のやり方で何かを指摘してください。私は入力が必要です。

しかし、私の主な関心事は、レイアウトの問題の原因を理解することです。ここではレイアウトの問題の性質を説明する二つの画像...

UPDATEです: は私だけ向きが横のとき、私はそれが水平になるように期待するとき、遷移は、垂直方向に反転していることに気づきました。私はそれが間違っているかもしれないことについてのヒントを知っていません。他のビュー...変更の方向へ

Normal Layout

スイッチ....切り替える....

Problem Layout

答えて

1

私はこの偶然見つけ、あなたが持っているので、気持ちを持っていますこれを考え出した。しかし、ちょうどその場合、あるいは他の誰かが同じ答えを探しているのであれば、これは私がその状況で取ったアプローチです。各View Controllerのヘッダファイル(あなたが切り替えるものではなく、ルートMyAppViewController)で

、フロートを追加:のviewDidLoadで

float boundWidth; 

を、0

boundWidth = 0; 

に初期化次に作成

- (void)viewDidAppear:(BOOL)animated { 
// check to see what orientation the device is in; 
    if ((boundWidth != 0) && (boundWidth != self.view.bounds.size.width)) { 
     // the orientation has changed, so insert code to deal with this; 
} 

次のようなチェックをしてください。あなたはビューを離れる:

- (void)viewDidDisappear:(BOOL)animated { 
    boundWidth = self.view.bounds.size.width; 
} 
関連する問題