2010-02-21 7 views
0

세로 화면에서 가로 화면 호출 코드를 작성하려고합니다. 현재 화면 방향이 가로 인 경우 아무런 자동 회전도 허용되지 않습니다.자동 회전을 비활성화하는 방법은 무엇입니까?

나는 다음 코드를 시도했다 :

// Override to allow orientations other than the default portrait orientation. 
/*- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
}*/ 

- (void)viewDidLoad { 

    [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight; 
    CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(90)); 
    landscapeTransform = CGAffineTransformTranslate(landscapeTransform, +90.0, +90.0); 
    [self.view setTransform:landscapeTransform]; 
} 

그러나 위의 코드

이 UIInterfaceOrientationLandscapeRight을 허용한다.

자동 회전을 비활성화하는 방법은 무엇입니까?

미리 감사드립니다.

답변

0

가로 모드에서 응용 프로그램을 시작 하시겠습니까? 모든 경우 shouldAutorotateToInterfaceOrientation 메서드를 재정의해야합니다.

그러나 응용 프로그램을 세로 모드로 시작한 다음 가로 모드로 이동하려면 정적 부울을 추가하여 대지 모드에 있어야하는지 여부를 알아야합니다. 응답

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    if(isInPortraitMode) { 
     // Return YES for supported orientations 
     return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
    } else { 
     if(interfaceOrientation == UIInterfaceOrientationLandscapeRight) { 
      isInPortraitMode = YES; 
     } 
     return YES; 
    } 
} 

- (void)viewDidLoad { 
    isInPortraitMode = NO; 
    //... 
} 
+0

감사 : 당신의 코드는 같은 모양해야합니다. 이전 버전에서 더 좋았습니다. 그러나 가로 모드에서 세로 모드를 허용합니다. 나는 어떤 방향이 될 수 없도록하려고 노력하고있다. 주기는 다음과 같습니다. 시작 -> 세로 -> 가로 -> 끝. – Ferdinand

관련 문제