0

私はいくつかの言葉でテーブルビューを持っています、そして私はデバイスが回転するときのフラッシュカードスタイルの横向きのビューを提示します。「UIDeviceOrientationDidChangeNotification」を見て作りました。

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(openLandscapeMode) name:@"UIDeviceOrientationDidChangeNotification" object:nil];

1)それは問題なくスムーズに機能しますが、問題は、私たちが風景の中にいるときに、ビューコントローラーが垂直軸の周りの回転に反応して、電話をテーブルに置くことができないようにすることです。まだ風景の中にあります。たぶん、デバイスの向きではなく、水平方向の回転をどうにかして観察する必要がありますか?

-(void)openLandscapeMode
{

    if([[UIDevice currentDevice]orientation]==UIDeviceOrientationLandscapeLeft||[[UIDevice currentDevice]orientation]==UIDeviceOrientationLandscapeRight)
    {
        LandscapeCardViewController *landscape = [[LandscapeCardViewController alloc]init];
        landscape.words = words;
        landscape.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
        [self presentModalViewController:landscape animated:YES];
        NSLog(@"Switch to %@",[[NSUserDefaults standardUserDefaults]valueForKey:@"ChosenWordInCard"]);
        [landscape release];
    }
    else
    {
        [self dismissModalViewControllerAnimated:YES];  
        [[UIApplication sharedApplication]setStatusBarOrientation:UIInterfaceOrientationPortrait];

    }
}

2)2番目の質問は、このコントローラーがタブバーにあり、同じタブバーの別のコントローラーで同じトランジションを実行したいが、もちろん別のランドスケープビューを使用している場合、オブザーバーを削除する場所です。viewWillDissappearで試しましたが、正しく機能しません。どうもありがとう!

4

2 に答える 2

2

最初の質問では、ポートレートのみをサポートするために編集する必要がある可能性のあるメソッドがビューコントローラにあるはずです。

-(BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationPortrait(interfaceOrientation); //only allow portrait
}

これにより、元の方法をそのままにしながら、横向きに自動回転するのを停止します

第二に。移行が完了したときはどうですか?次に、ビューが再び表示されたら、それを再度追加します。次に、ランドスケープコントローラーに追加して、デバイスがポートレートの場合に再検出します。

于 2012-03-07T11:51:16.643 に答える
0

私は他に変更した解決策を見つけました、if([[UIDevice currentDevice]orientation]==UIDeviceOrientationPortrait||[[UIDevice currentDevice]orientation]==UIDeviceOrientationPortraitUpsideDown)そしてすべてがうまくいきます!奇妙ですが、うまくいきます!

オブザーバーの削除について-私は-viewWillAppear今風景にいない場合は、チェックでそれを行います。

于 2012-03-27T18:45:44.303 に答える