Development Tip

현재 인터페이스 방향을 얻는 다른 방법?

yourdevel 2020. 11. 23. 20:18
반응형

현재 인터페이스 방향을 얻는 다른 방법?


내가 아는 현재 인터페이스 방향을 얻는 방법에는 세 가지가 있습니다.

  • 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

반응형