2010-06-03 6 views
3

iPhone/iPad에서 화면의 방향을 결정하는 방법이 있는지 궁금했습니다.iPhone/iPad 화면의 현재 방향을 어떻게 쿼리 할 수 ​​있습니까?

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    self.orientation = interfaceOrientation; 
    return YES; 
} 

... 뭔가 느낌있는 내가 대신이 변경 될 때를 추적하는 데의 상태로 조회 할 수 있어야한다 :

현재 나 자신이 메시지가 호출되는 멤버 변수를 설정 찾기 .

답변

11

UIViewController에는 interfaceOrientation 속성이 있습니다.

UIDevice에서 방향에 의해 혼동하지 마십시오. 인터페이스의 방향이 아니라 물리적 방향입니다.

+0

그것은 미묘하지만 중요한 차이입니다. 답변 해주셔서 감사합니다. – ra9r

+0

은 iOS8에서 가치가 하락했습니다. 문서 도구 추천 :'viewWillTransitionToSize : withTransitionCoordinator : ' – SimplGy

1

[[UIDevice currentDevice] orientation]을 사용할 수 있습니다.

+1

이것은 올바른 인터페이스 방향이 아닙니다. 설명서에서 "orientation 속성은 이러한 상수를 사용하여 장치 방향을 식별합니다.이 상수는 장치의 실제 방향을 나타내며 응용 프로그램의 사용자 인터페이스 방향에 종속되지 않습니다." – Eiko

11

상태 표시 줄이 위에있는 경우 사용하십시오.

UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; 
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) { 
    // portrait    
} else { 
    // landscape 
} 
+0

내 UIView의 방향을 반환합니까? – iOmi

관련 문제