현재 인터페이스 방향을 얻는 다른 방법?
내가 아는 현재 인터페이스 방향을 얻는 방법에는 세 가지가 있습니다.
self.interfaceOrientation
[[UIApplication sharedApplication] statusBarOrientation]
[[UIDevice currentDevice] orientation]
그들 사이의 차이점은 무엇입니까?
self.interfaceOrientation
인터페이스의 현재 방향 인 UIInterfaceOrientation을 반환합니다. UIViewController의 속성이며 UIViewController 클래스에서만이 속성에 액세스 할 수 있습니다.
[[UIApplication sharedApplication] statusBarOrientation]
응용 프로그램 상태 표시 줄의 현재 방향 인 UIInterfaceOrientation을 반환합니다. 애플리케이션의 어느 지점에서나 해당 속성에 액세스 할 수 있습니다. 내 경험에 따르면 실제 인터페이스 방향을 검색하는 더 효과적인 방법입니다.
[[UIDevice currentDevice] orientation]
UIDeviceOrientation , 장치 방향을 반환 합니다 . 애플리케이션의 어느 지점에서나 해당 속성에 액세스 할 수 있습니다. 그러나 UIDeviceOrientation이 항상 UIInterfaceOrientation은 아닙니다. 예를 들어 장치가 일반 테이블에 있으면 예기치 않은 값을받을 수 있습니다.
[[UIApplication sharedApplication] statusBarOrientation]
-항상 세로, 가로 왼쪽, 가로 가로 및 세로 거꾸로 된 네 가지 값 중 하나와 같습니다.
[[UIDevice currentDevice] orientation]
-이것은 표준 네 가지 값과 같으며 또한 알 수 없음, 앞면이 위 또는 아래를 향합니다.
[[UIApplication sharedApplication] statusBarOrientation]
-인터페이스 방향을 얻는 데 더 선호되는 방법입니다.
모든 뷰 컨트롤러에는이 기능이 있습니다.
override func didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation) {
//fromInterfaceOrientation.isLandscape
}
또는 상태 표시 줄 방향을 사용할 수 있습니다.
if UIApplication.sharedApplication().statusBarOrientation == UIInterfaceOrientation.Portrait {
//
}
iOS 9에서 작동합니다. :)
참고 URL : https://stackoverflow.com/questions/7968451/different-ways-of-getting-current-interface-orientation
'Development Tip' 카테고리의 다른 글
기본 클래스 생성자를 어떻게 호출합니까? (0) | 2020.11.23 |
---|---|
matplotlib를 사용하여 두 그림을 표시하는 방법은 무엇입니까? (0) | 2020.11.23 |
위치 인수 대 키워드 인수 (0) | 2020.11.23 |
사전 구현에 가장 적합한 데이터 구조? (0) | 2020.11.23 |
Chrome 개발자 패널에 요소 선택기에 대한 키보드 단축키가 있습니까? (0) | 2020.11.23 |