2011-12-30 2 views
1

UINavigationController를 세로로 표시하는 가로 방향의 UIViewController가 있습니다. 모달 연결 추적을 사용하여보기 컨트롤러에서 탐색 컨트롤러로 이동할 때 처음에는보기 컨트롤러가 처음에는 세로 방향으로 강제됩니다 (처음에는 가로 방향이어야 함). segue를 제거하면 예상대로 작동합니다.연속보기를 사용하여보기 자동으로 회전

원하는 동작은 가로 방향의 인터페이스에서 세로 방향의 다른 인터페이스로 모달 세구를 사용하는 것입니다.

여기에 무슨 일이 일어나고 있는지 아십니까? 또는 의도 한대로 작동시키는 방법?

답변

0

알림을 사용하십시오.

-(void)viewWillAppear:(BOOL) animated{ 
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
[[NSNotificationCenter defaultCenter] addObserver: self selector:@selector(receivedRotate:) name: UIDeviceOrientationDidChangeNotification object: nil]; 
} 

-(void) receivedRotate: (NSNotification*) notification 
{ 
UIDeviceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation]; 
if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft) 
{ 
    [self performSegueWithIdentifier:@"/* Segue from the VCPotrait to VCLandscape*/" sender: self]; 
} 
} 

구획은 모달이어야합니다.

+0

흠, 난 당신이 내 질문을 오해 생각합니다. 모달 뷰 컨트롤러를 열면 iPhone이 방향을 변경하는 방법을 알고 싶습니다. 나는 이미 사용자에 의해 야기 된 방향을 다루는 방법을 알고있다. –

+0

기기 방향 속성이 있다고 생각합니다. 이렇게하면 방향을 설정할 수 있습니다. – Faser

+0

UIDevice의 방향 속성을 말하는 경우 읽기 전용입니다. –

0

처음에 내비게이션 컨트롤러가 세로 방향으로 설정되어야합니까?

나는 UIViewController 하위 클래스에서이를 수행했습니다. 여기서 뷰 컨트롤러는 가로 방향으로 뷰 컨트롤러에 모달 세그먼트를 수행하는 세로 방향으로 있습니다. 열쇠는 내가 원하는하지 않은 어떤 방향으로 자동 회전하지 않도록 두 번째 컨트롤러를 말하고 있었다 :

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft); 
} 

당신이 부분을 설정 할 수 UINavigationController가 서브 클래스 싶을 것이다, 나는 생각한다.

SEGUE는 스토리 보드에 모달로 정의하고, 첫 번째 (발표자) 뷰 컨트롤러의 코드는 매우 정상적인 모습입니다 :

-(IBAction) zoomIn:(id)sender { 
    [self performSegueWithIdentifier:@"ZoomIn" sender: self]; 
} 

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
    if ([[segue identifier] isEqualToString:@"ZoomIn"]) { 
     OSZoomViewController *zoom = [segue destinationViewController]; 
     zoom.image = ...; 
     zoom.presenter = self; 
    } 
} 
관련 문제