2012-03-18 14 views
0

2つのビューの間でスイッチにエフェクトを追加しようとしています。切り替えはデバイスを回転させるだけです。これまでのところ、ポートレートから風景に変わったときに効果を適用することはできますが、逆のことは適用できません。ここでトランジション効果でビューを切り替える

は私のコードです:このように

-(void)orientationChanged:(NSNotification *)object{ 
UIDeviceOrientation deviceOrientation = [[object object] orientation]; 
if (deviceOrientation == UIInterfaceOrientationPortrait) 
{ 
    /* If I run with this block, I have a Exc Bad Access Error and can't run, so I put it 
     under comment 

    [UIView transitionWithView:self.view duration:1.0 
options:UIViewAnimationOptionTransitionCrossDissolve 
        animations:^{ 
         [self.view addSubview:self.portraitView]; 
        } completion:NULL]; 
    */ 

    self.view = self.portraitView; 

    //[self dismissModalViewControllerAnimated:YES]; 

} 
else if (deviceOrientation == UIInterfaceOrientationLandscapeLeft || deviceOrientation == 
UIInterfaceOrientationLandscapeRight) 
{ 
    [UIView transitionWithView:self.view duration:1 
options:UIViewAnimationOptionTransitionCrossDissolve 
        animations:^{ 
         [self.view addSubview:self.landscapeView]; 
        } completion:NULL]; 
    [self dismissModalViewControllerAnimated:NO]; 
} 
} 

landscapeViewの遺跡、ポートレートから風景に渡すとき、私は望ましい効果を持っていますが、私は戻って縦にデバイスを置くとき、それはportraitViewをロードしません。に。 誰かが私を助けることを願っています。

編集:私はちょうどこのように、私の上記のコードを編集した

-(void)orientationChanged:(NSNotification *)object{ 
UIDeviceOrientation deviceOrientation = [[object object] orientation]; 
if (deviceOrientation == UIDeviceOrientationPortrait) 
{ 

    if (self.isViewLoaded && self.view.window) 
    { 
    NSLog(@"Portrait1"); 
    [UIView transitionWithView:self.view duration:1 
    options:UIViewAnimationOptionTransitionCrossDissolve 
        animations:^{ 
         NSLog(@"Portrait2"); 
         [self.view.window addSubview:self.portraitView]; 
        } completion:NULL]; 
    [self dismissModalViewControllerAnimated:YES]; 
    } 
} 
else if (deviceOrientation == UIDeviceOrientationLandscapeLeft || deviceOrientation == 
UIDeviceOrientationLandscapeRight) 
{ 

    [UIView transitionWithView:self.view duration:1 
options:UIViewAnimationOptionTransitionCrossDissolve 
        animations:^{ 
         [self.view addSubview:self.landscapeView]; 
        } completion:NULL]; 
    [self dismissModalViewControllerAnimated:NO]; 
    NSLog(@"Landscape"); 
} 
} 

そして効果が正常に動作します。しかし私は大きな問題を抱えています。私は風景から肖像画に戻ったとき、landscapeViewはportraitViewのままです。どのように私はそれを却下することができますか?

+0

私はそれを試したことはありませんが、UIDeviceOrientationとUIInterfaceOrientationを混ぜているという事実とは関係があり、2番目のif文では運が良かったと思います。しかし、悪いアクセスエラー。最初のif文をデバッグしているときにNSLog()を持っていましたか? – Aky

+0

私はあなたが言っていることを理解できません。私は[self.view addSubview:self.landscapeView]にエラーがあります。ライン。だから、NSLogをそのすぐ上の行に置き、それをデバッグウィンドウに表示します。これはあなたが話していることですか? – Enzoses

+0

私のコードを編集しました。どうぞご覧ください。 – Enzoses

答えて

0

デバイスの向きがUIDeviceOrientationPortraitになったときに、あなたの更新コードを参照すると、self.viewではなくself.view.windowにportraitviewをサブビューとして追加するのは間違いです。

また、[self dismissModalViewControllerAnimated:NO]の背後にある目的は何ですか?モーダルビューコントローラは実際にはどこにも表示されていないため、目的を果たせません。

+0

実際、self.viewでExc Bad Access Errorが発生したので、.windowを追加しました。 [self dismissModalViewControllerAnimated:NO]は、問題を解決しようとする私の多くのショットの1つでした。私はそれをキャンセルした。 – Enzoses

+0

正確なエラーは次のとおりです。スレッド1:EXC_BAD_ACCESS(コード= 2、アドレス= 0xbf7ffffbc)、左側に43664 __37- [ViewController orientationChanged:] _ block_invoke_0 – Enzoses

関連する問題