1

デバイスを回転させたときにビューのレイアウトを変更しようとして問題が発生しました。メインビューはOverviewViewControllerと呼ばれ、デバイスが特定の方向にあるときに非表示/表示される2つのビューで構成されています。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{    
     // do some layout stuff
     NSLog(@"OverviewViewController shouldAutorotateToInterfaceOrientation");
     return YES;
}

デバイスを回転させるたびに、このメソッドは2回実行されますが、たとえば、どのサブビューでも呼び出されることはありません。

// In OverviewViewController

_landscapeView = [[LandscapeOverviewViewController alloc] initWithNibName:nil bundle:nil];
[self.view addSubview:_landscapeView.view];


// In LandscapeOverviewViewController

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{    
    NSLog(@"LandscapeOverviewViewController: shouldAutorateToInterfaceOrientation");

    // Only change orientation when it's landscape
    if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) return YES;
    return NO;
}

サブビューがデバイスの向きに応答しない理由はありますか?メソッドがそこで呼び出されることはありません。

4

2 に答える 2

3

ご覧のとおり、LandscapeOverviewViewControllerビューをサブビューとしてに追加していself.viewます。
そして、あなたはあなたLandscapeOverviewViewControllershouldAutorotateToInterfaceOrientationが決して起こらないように呼ばれることを望みます。
これらはあなたがしているようであるpushedかどうかにかかわらず、そのコントローラーに呼び出されpresentedます。

解決策: 2つのことができます
1。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{    
     // do some layout stuff
     NSLog(@"OverviewViewController shouldAutorotateToInterfaceOrientation");
     //Call explicitly shouldAutorotateToInterfaceOrientation of LandscapeOverviewViewController
     [_landscapeView shouldAutorotateToInterfaceOrientation:interfaceOrientation];
     return YES;
}


2.オリエンテーション通知はで登録できますLandscapeOverviewViewController

于 2012-07-30T03:36:12.547 に答える
0

あなたのoverviewViewController内で2つの別々のviewcontrollers(各方向に1つ)を使用する必要がありますか?

向きに基づいてフレーム値を変更するだけの場合は、必ず自動サイズ変更マスクを使用してください。

そうでない場合は、方向ごとに個別のビューを使用し、必要に応じて各ビューを非表示にします。

現在の問題は、lanscapeViewControllerにviewControllerEventsを送信する人がいないことです。

現在の設定では、OverviewViewControllerのこのコードを使用して、これらのビューコントローラーをモーダルに表示できます。

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration{
{    
    if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
        [self presentModalViewController:LandscapeOverviewViewController animated: NO];
        }
    else{
       [self presentModalViewController:PortraitOverviewViewController animated: NO];
       }
}
于 2012-07-30T03:36:57.883 に答える