私はビットごとに少し迷っています;)
私の目標は、アプリケーションでサポートされている向きのセット全体を取得し、各結果値をテストしてカスタム変数を更新することです。私の問題は、比較を行う方法がわからないことです(変換/テストの問題が発生しました...)
最初にこの記事を読みました:ビットごとの列挙値のテスト しかし、それは私に光をもたらしません...
アプリケーションに対して次の方向宣言があるとします (以下は変数supportedOrientationsのログ出力です): supported orientations = ( UIInterfaceOrientationPortrait )
したがって、私の最初の試みは整数値でいくつかのテストを試みることでしたが、機能しません(アプリケーションがポートレートモードであると宣言されていても、テストは「false」を返します):
NSArray *supportedOrientations = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UISupportedInterfaceOrientations"];
NSLog(@"[supported orientations = %@", supportedOrientations);
// for clarity just make a test on the first orientation we found
if ((NSInteger)supportedOrientations[0] == UIInterfaceOrientationPortrait) {
NSLog(@"We detect Portrait mode!");
}
私の 2 番目の試みは、ビットごとのことを試すことでしたが、今回は常に「true」を返します (サポートされている方向が UIInterfaceOrientationPortrait でない場合でも)。:
NSArray *supportedOrientations = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UISupportedInterfaceOrientations"];
NSLog(@"[supported orientations = %@", supportedOrientations);
// for clarity just make a test on the first orientation we found
if ((NSInteger)supportedOrientations[0] | UIInterfaceOrientationPortrait) { // <-- I also test with UIInterfaceOrientationMaskPortrait but no more success
NSLog(@"We detect Portrait mode!");
}
だから私の質問は:
私の場合、向きをテストするにはどうすればよいですか?
ビットごとのもの(|オペランドを使用)を使用してテストを使用する方法ですか?