2011-06-24 3 views
1

ビューを縦方向と横方向とで大きく異なる必要があるため、回転のビューを変更しようとしています。今では私が使っているコードは一回しか動かず、回転しないとフリーズします。どちらの方向でも違いはありません。たとえば、私が風景にあり、肖像画に回転していると、すべて風景に戻って凍ってしまい、全く何もしなくなるまで、すべてがうまくいきます。iPadでUIInterfaceOrientation中にUIViewを変更する

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return YES; 
} 

- (void)didRotate:(NSNotification *)notification 
{   
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; 

    if ((orientation == UIDeviceOrientationLandscapeLeft) || 
     (orientation == UIDeviceOrientationLandscapeLeft)) 
    { 
     // present the other viewController, it's only viewable in landscape 
     [self.view addSubview:landScapeView]; 
    } 

    if ((orientation == UIDeviceOrientationLandscapeRight) || 
     (orientation == UIDeviceOrientationLandscapeRight)) 
    { 
     // present the other viewController, it's only viewable in landscape 
     [self.view addSubview:landScapeView]; 
    } 
    else if ((orientation == UIDeviceOrientationPortrait || 
      (orientation == UIDeviceOrientationPortrait)) 
    { 
     // get rid of the landscape controller 
     [self.view addSubview:portrait]; 
    } 
    else if ((orientation == UIDeviceOrientationPortraitUpsideDown || 
      (orientation == UIDeviceOrientationPortraitUpsideDown)) 
    { 
     // get rid of the landscape controller 
     [self.view addSubview:portrait]; 
    } 
} 
+0

次回質問をするときにコードを適切に書式設定する時間を取ってください。読みやすくするために、より良い回答が得られます。また、 'if/else'条件で同じ値に対して' orientation'変数を2回チェックしている理由を正確にはわかりません。このコードを単純化する必要があります。 –

+0

申し訳ありませんが、通常、私は...遅くなっています。それを修正するためにありがとう! – FreeAppl3

答えて

2

あなたを追加している:ここでは

が、私は私の「のviewDidLoad」メソッドでは、この

を達成するために使用していたコードである

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];  
[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(didRotate:) 
              name:UIDeviceOrientationDidChangeNotification 
              object:nil];  

は、その後、私は回転のためにこれを呼び出しますあなたが必要とするので、他のものを決して削除しないで、回転でオリエンテーション特有のビュー。

// get rid of the landscape controller 
    ((orientation == UIDeviceOrientationPortraitUpsideDown || orientation == 
UIDeviceOrientationPortraitUpsideDown)) { 

[landScapeView removeFromSuperview];  
[self.view addSubview:portrait]; 
    } 

他の方向でも同様です。

スーパービューリリースから削除することで、両方のビューを外部に保持する必要があることに注意してください。

+0

私は応答を感謝します。意味がある、私はこれを試みたが、私は解決する必要があるいくつかのことがある。あなたは間違いなく正しい方向に私を送りました!ありがとうございました! – FreeAppl3

関連する問題