2012-05-21 2 views
4

스토리 보드에 5 개의보기가 있습니다. 각보기의 방향이 달라지기를 원한다면 하나의보기가 UIInterfaceOrientationLandscapeRight이고 다른보기는 UIInterfaceOrientationLandscapeLeft 또는 UIInterfaceOrientationPortrait 또는 UIInterfaceOrientationPortraitUpsideDown이됩니다. 그렇다면이 방향성을 어떻게 다르게 설정해야할까요?런타임시 UIInterfaceOrientation을 설정하십시오.

나는 [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight]; 을 사용하고 있지만 경고 'UIDevice이 setOrientation에 응답하지 않을 수 있습니다'을 보여줍니다. 많은 사용 stackoverflow 작가에 따르면

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { 
    //return UIInterfaceOrientationLandscapeLeft; 
    return (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown); 
} 

위의 코드가 있지만 내 프로젝트에서 작동하지 않습니다. 화면의 방향을 결정하는 적절한 절차는 무엇입니까? 미리 감사드립니다.

답변

2

은 물리적 매개 변수이기 때문에 당신은 UIDeviceOrientation를 설정 두지이

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:YES]; 

을보십시오. 손에 장치를 세로로 유지하면 프로그래밍 방식으로 가로로 설정하는 방법). UIDeviceOrientation은 인터페이스가 아니라 장치 오리 엔테이션을 의미합니다. 이 답변은 방위 간의 차이점을 설명합니다. https://stackoverflow.com/a/3897243/194544

+0

내 장치를 프로그래밍 방식으로 세로 모드로 유지할 수있는 방법이 있습니까? – Banshidhari

+0

세로 방향의 경우 shouldAutorotateToInterfaceOrientation에서 반환을 유지합니다. – beryllium

0

-(BOOL)shouldAutorotateToInterfaceOrientation:을 각 viewController에 입력하고 올바른 방향을 확인해야합니다. 예를 들어 지원하는 viewController를 밀면. upsideDown, 그것은 거꾸로 제시됩니다.

참고 :

당신이 TabBar의 환경에있는 경우
  • , 동작이 다릅니다. 그렇다면 물어보십시오. 당신이 rootViewController에 대해 이야기하는 경우
  • 앱이 최초의 ViewController (의 Info.plist)에 해당하는 설정해야
0

UIDevice의 방향 속성입니다 읽기 전용.

[UIViewController attemptRotationToDeviceOrientation];을 사용하면 모든보기 컨트롤러를 장치의 현재 방향으로 회전 할 수 있습니다. 강제로 회전을 설정할 수 없습니다.

관련 문제