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のままです。どのように私はそれを却下することができますか?
私はそれを試したことはありませんが、UIDeviceOrientationとUIInterfaceOrientationを混ぜているという事実とは関係があり、2番目のif文では運が良かったと思います。しかし、悪いアクセスエラー。最初のif文をデバッグしているときにNSLog()を持っていましたか? – Aky
私はあなたが言っていることを理解できません。私は[self.view addSubview:self.landscapeView]にエラーがあります。ライン。だから、NSLogをそのすぐ上の行に置き、それをデバッグウィンドウに表示します。これはあなたが話していることですか? – Enzoses
私のコードを編集しました。どうぞご覧ください。 – Enzoses