2013-03-09 1 views
0

순간에만 초상화 인 앱에 가로 방향 지원을 추가하지만 방향을 자동으로 회전 시키거나 세로 방향으로 잠글 수 있도록 구성 가능하게하려고합니다 또는 풍경. .plist에서 iOS 상수 (UIApplication.h의)를 사용합니다.

내 기본 설정 지정자

는 다음과 같다 :

<dict> 
     <key>Type</key> 
     <string>PSMultiValueSpecifier</string> 
     <key>Title</key> 
     <string>Orientation</string> 
     <key>Titles</key> 
     <array> 
      <string>Auto Rotate</string> 
      <string>Landscape</string> 
      <string>Portrait</string> 
     </array> 
     <key>Values</key> 
     <array> 
      <string>1</string> 
      <string>2</string> 
      <string>3</string> 
     </array> 
     <key>Key</key> 
     <string>bz-orientation</string> 
     <key>DefaultValue</key> 
     <string></string> 
    </dict> 

가 대신 기본 설정 값을위한 매직 넘버를 가지고, 나는 실제로 UIApplication.hUIInterfaceOrientationMaskAll에서 UIInterfaceOrientationMask 값을 사용하려면, UIInterfaceOrientationMaskLandscape & UIInterfaceOrientationMaskPortrait

이것을 달성하기 위해 어쨌든 있습니까?

답변

0

내가 알 수있는 한 직접적으로는 아닙니다. 그러나 일부 사전 처리기 악용과 함께, 당신은 일정한 텍스트 (또는 다른 방법으로)지도를 해킹 할 수 있고 plist에서 문자열을 사용할 수 있습니다.

#define ENTRY(constant) @#constant: [NSNumber numberWithInteger:constant] 

NSDictionary *orientations = @{ 
    ENTRY(UIInterfaceOrientationMaskAll), 
    ENTRY(UIInterfaceOrientationMaskLandscape), 
    ENTRY(UIInterfaceOrientationMaskPortrait) 
}; 

#undef ENTRY 

그런 다음

<key>Values</key> 
<array> 
    <string>UIInterfaceOrientationMaskAll</string> 
    <string>UIInterfaceOrientationMaskLandscape</string> 
    <string>UIInterfaceOrientationMaskPortrait</string> 
</array> 

처럼 뭔가 설정 번들을 plist에 관련 조각을 변경하고 실제 인터페이스 방향 마스크를 검색하기 위해 :

NSUserDefaults *defs = [NSUserDefaults standardUserDefaults]; 
NSString *maskAsString = [defs objectForKey:@"bz-orientation"]; 
NSNumber *maskAsNumber = [orientations objectForKey:maskAsString]; 

// Enum types are often just typedeffed to `NSInteger` or `NSUInteger` 
UIInterfaceOrientationMask mask = [maskAsNumber integerValue]; 
+0

을이 무슨 뜻인지입니다 고마워요. 내가 생각한 경로 였지만 다른 방법이 없다는 것을 확인하고 싶었던 경로였습니다. (C가 있지만 iOS/ObjC는 조금 새로운 것입니다.) –

관련 문제