0

私のアプリでは、デバイスを逆さまに回転させたいと思っています。これは正常に機能しています。ただし、アプリが特に回転しないようにしたい

左の風景->右の風景-およびその逆

誰かが興味を持っている場合、これは、それぞれが共通のポイントから回転するため、その回転が私のレイアウトを台無しにするためです

私がうまくいくと思うiOS5のコードは、次のようになります。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {

    NSLog(@"Rotating");
    if((lastOrient == 3 && toInterfaceOrientation == 4) || (lastOrient == 4 && toInterfaceOrientation == 3)){
       lastOrient = toInterfaceOrientation;
       return NO;
    }

   lastOrient = toInterfaceOrientation;
   return YES;

}

ここで、3 =左の風景、4=右の風景

iOS6でこれを行う方法について何か提案はありますか?または完全に異なる解決策?

4

2 に答える 2

1

shouldAutorotateToInterfaceOrientationはios6で非推奨になりました。これを使って:

- (BOOL)shouldAutorotate {

UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];

if (lastOrientation==UIInterfaceOrientationPortrait && orientation == UIInterfaceOrientationPortrait) {
 return NO;

}

return YES;
}

このコードはテストしていません。これらの投稿に関する詳細情報を入手できます 。iOS6ではshouldAutorotateToInterfaceOrientationが機能していませ んiOS6ではshouldAutorotateToInterfaceOrientationが呼び出されていません

于 2012-11-27T21:17:41.490 に答える
0

わかりました、私はここで私自身の質問に答えました:

良いニュースは、これを行う方法が間違いなくあるということです!だからここに基本があります:

iOS6では、アプリが一般的に回転できるかどうかを処理するのはappDelegate次第です。次に、デバイスが回転信号を受信すると、サポートされている方向をビューに要求します。ここにコードを実装しました。実際、shouldAutorotate()はソリューションでは何の役割も果たしません。

だから私は最後の方向を追跡するために変数を作成し、それを変更します

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{

このようにして、向きを比較できます

-(NSUInteger)supportedInterfaceOrientations
{
    NSLog(@"Last Orient = %d", lastOrient);
    NSUInteger orientations = UIInterfaceOrientationMaskPortrait;

    if (lastOrient != 3 && lastOrient != 4) {
        NSLog(@"All good, rotate anywhere");
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
    else if(lastOrient == 3){
        orientations |= UIInterfaceOrientationMaskLandscapeRight;
        NSLog(@"Can only rotate right");
    }
    else if(lastOrient == 4){
        orientations |= UIInterfaceOrientationMaskLandscapeLeft;
        NSLog(@"Can only rotate left");
    }

    return orientations;
}

私のために働くようです。少しハックしますが、必要なことを実行します

于 2012-11-27T21:20:32.220 に答える