1

コンテナ コントローラの向きに問題があります。

コントローラーを切り替えると、前のコントローラーは、元に切り替えたときに中断した方向にとどまる傾向があります。

向きのバグ

まず、再現に使用する手順:

  1. コンテナ コントローラが表示されたら、横向きに回転します。この時点で、ランドスケープではすべてがうまく見えます。
  2. セグメント化されたコントロールを介して子コントローラー #2 に切り替えます。
  3. このビューで回転して横向きに戻します。すべてはまだ正常に見えます。
  4. 子コントローラー #1 に戻ります。

ContainerController の viewDidLoad で:

self.child1 = [self.storyboard instantiateViewControllerWithIdentifier:@"first"];
self.child2 = [self.storyboard instantiateViewControllerWithIdentifier:@"second"];

[self addChildViewController:self.child1];
[self addChildViewController:self.child2];

[self.view addSubview:self.child1.view];

子コントローラーを移行する方法:

- (IBAction)segmentChanged:(id)sender
{
    UIViewController *toVc, *fromVc;
    UISegmentedControl *segment = sender;

    if (segment.selectedSegmentIndex == 0)
    {
        toVc = self.child1;
        fromVc = self.child2;  
    }
    else
    {
        toVc = self.child2;
        fromVc = self.child1;
    }

    [toVc willMoveToParentViewController:self];
    [self transitionFromViewController:fromVc 
                      toViewController:toVc 
                              duration:0.0
                               options:UIViewAnimationOptionTransitionNone 
                            animations:nil
                            completion:^(BOOL finished){
                                [toVc didMoveToParentViewController:self];
                            }];
}

私は、transitionFromViewController がそのすべてを自動的に処理すると想定していました。私が間違っていることを誰かが知っていますか?

4

2 に答える 2

2

簡単な解決策は、transtionFromViewController 関数が呼び出される前に次の行を追加することです。

toVc.view.frame = self.view.bounds;

これにより、新しいビューでフレームが正しく設定されます

于 2012-06-01T19:54:56.940 に答える
1

I like Omar Abdelhafith's answer. While it will set the frame, it may not rotate the view to the desired orientation. You will have to test for that. What can also be done is to check the orientation of the status bar. Then call the willRotateToOrientation method sending the orientation of the status bar. I hope this also helps.

于 2012-06-02T03:09:29.300 に答える