2013-09-27 1 views
0

내가 비트 손실 조금 있어요 값 만들려면) 내 목표는 응용 프로그램에서 지원 방향의 전체 집합을 검색하고 갱신하기 위해 각각의 결과 값을 테스트하는 것입니다UIInterfaceOrientation 열거와 시험

을 맞춤 변수 Testing for bitwise Enum values 를하지만 나에게 빛을 가져다하지 않습니다 .. : 내 문제는 내가 비교를 만드는 방법을 알고하지 않는 것이 우선이 글을 읽을

(나는 ... 변환/시험 문제를 가지고) .

하자 내가 내 응용 프로그램에 대한 선언 다음과 같은 방향을 가지고 있다고 (다음 내 변수 supportedOrientations에 대한 로그 출력) : (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) { 
    NSLog(@"We detect Portrait mode!"); 
} 

내 두 번째 시도는 비트 일을 시도했다하지만, 이번에는 항상 '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!"); 
} 

그래서 제 질문은 :

  • 어떻게 내 경우 방향을 테스트하기 위해?

  • 비트 피하기 (피연산자 사용)를 사용하여 테스트를 사용하는 방법입니까?

답변

0

공식 문서는 UISupportedInterfaceOrientations 문자열의 배열이라고 말했다. https://developer.apple.com/library/ios/documentation/general/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW10

따라서 해결책은 배열에서 발견 된 각 요소에 대해 NSString 비교를 사용하는 것입니다. 이 같은 일을하는 것은 우리가 (유형 UIInterfaceOrientation의) 열거 값을 활용하지 못했지만, 그것을 작동

NSArray *supportedOrientations = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UISupportedInterfaceOrientations"]; 
for (NSString *orientation in supportedOrientations) {   
    if ([orientation isEqualToString:@"UIInterfaceOrientationPortrait"] || 
     [orientation isEqualToString:@"UIInterfaceOrientationPortraitUpsideDown"]) { 
     NSLog(@"*** We detect Portrait mode!"); 
    } else if ([orientation isEqualToString:@"UIInterfaceOrientationLandscapeLeft"] || 
       [orientation isEqualToString:@"UIInterfaceOrientationLandscapeRight"]) { 
     NSLog(@"*** We detect Landscape mode!"); 
    } 
} 

주의!