Hi yoahn 개발블로그

[iOS] safeArea 사용하기 본문

프로그래밍 언어/iOS

[iOS] safeArea 사용하기

hi._.0seon 2021. 2. 4. 20:52
반응형

study 를 진행하면서 ImageView의 레이아웃을 잡아야 했는데, 위치를 잡는 과정에서 iPhone X 이상 모델에서 노치로 인한 SafeArea 위치를 파악하여 safeArea에 view를 잡는 과정이 필요했는데, 드디어 알아내서 기록해두려고 한다

 

먼저 Swift - iOS 13.0 이상

let window = UIApplication.shared.windows[0]
let topPadding = window.safeAreaInsets.top
let bottomPadding = windows.safeAreaInsets.bottom

SafeArea 영역

topPadding 은 위 사진에서 상단에 위치한 녹색 영역의 높이를 나타내고,

bottomPadding 은 위의 사진에서 하단에 위치한 녹색 영역의 height 크기를 의미한다.

 

변수에 저장한 padding 값을 코드로 뷰의 위치를 지정할 때 사용하면 된다.

 

 

stackoverflow.com/questions/46829840/get-safe-area-inset-top-and-bottom-heights/53864017#53864017

 

Get safe area inset top and bottom heights

On the new iPhone X, what would be the most proper way to get both top and bottom height for the unsafe areas?

stackoverflow.com

devmjun.github.io/archive/SafeArea_1

 

Swift, Safe Area에 대해서 알아봅니다.

 

devmjun.github.io

위 링크에 나오는 내용들은 적용이 안되는 것 같은데 댓글로 알려주시면 감사합니다:)

반응형
Comments