2011-09-06 2 views
0

유니버셜 앱용 코드는 다음과 같지만 앱을 실행할 때 이상한 로그가 표시됩니다. 그러나 모든 것이 잘 작동하는 것 같습니다. 콘솔에서 유니버설 앱으로 자동 회전하는 비정상적인 디버그 로그 받기

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    if (NSClassFromString(@"UISplitViewController") != nil && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
    { 
     return YES; 
    } 
    else 
     return NO; 
} 

는 :

The view controller <UINavigationController: 0x1468d0> returned NO from -shouldAutorotateToInterfaceOrientation: for all interface orientations. It should support at least one orientation. 

답변

2

메시지는 말합니다 모든 :

그것은 적어도 하나 개의 방향을 지원해야한다.

else 문에는 방향에 관계없이 NO 문이 반환됩니다. NO 여기에서 의미하는 경우 "초상화를 전용"체크를하고 초상화 YES을 반환 :

else 
return 
    (interfaceOrientation == UIInterfaceOrientationPortrait) ? 
    YES : 
    NO ; 

또는 더 간결 (미만 애호가) 버전 :

else 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
0

나는 그 것을 의미한다고 생각하여 조건이 항상 false 인 경우. iPad인지 UISplitViewController 클래스인지에 관계없이 세로 또는 가로 모두 YES를 반환하는 경우가 항상 있습니다. 당신의 아이폰은 항상 NO를 반환합니다. 더 이런 식으로 뭔가 시작하고 아마 blahblah 경우에만 풍경을 허용 :

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
    { 
    if (NSClassFromString(@"UISplitViewController") != nil && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
    { 
     return YES; 
    } 
    else 
    { 
     // Return YES for supported orientations 
     return (interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown); 
    } 
0

내가 생각 항상 if 조건 실패 할 가능성이 있으므로 항상 "나는 어떤 방향을 지원하지 않습니다"라는 뜻의 NO을 반환합니다. 이는 분명히 사실이 아닙니다 ... 지원하고 싶은 가장 낮은 대상은 무엇입니까? 당신의 else가 아이폰/아이팟을 처리하도록되어있는 경우

, 당신은 적어도 하나의 방향을 YES을 반환해야합니다 :

return (interfaceOrientation == UIInterfaceOrientationPortrait); 

또는

return inOrientation == UIDeviceOrientationLandscapeLeft 
    || inOrientation == UIDeviceOrientationLandscapeRight 
    || inOrientation == UIDeviceOrientationPortrait 
    || inOrientation == UIDeviceOrientationPortraitUpsideDown; 

모든 방향을 지원하려는 경우

.

3.2보다 낮은 iOS 버전을 지원하고 시뮬레이터에서 테스트하고 싶다면 "iPad 확인"을 다음과 같이 변경하십시오.

- (BOOL)amIAnIPad { 
    // This "trick" allows compiling for iOS < 3.2 and testing on pre 3.2 simulators 
#if (__IPHONE_OS_VERSION_MAX_ALLOWED >= 30200) 
    if ([[UIDevice currentDevice] respondsToSelector: @selector(userInterfaceIdiom)]) 
     return ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad); 
#endif 
    return NO; 
} 

그 트릭에 대한 자세한 내용은 Jeff LaMarche's blog에서 확인할 수 있습니다.

관련 문제