Jiwift

[iOS/Swift] safeAreaInsets 상단, 하단 영역 구하기 본문

iOS Dev/iOS

[iOS/Swift] safeAreaInsets 상단, 하단 영역 구하기

지위프트 2024. 4. 23. 20:37
반응형

safearea의 상단, 하단 insets을 구하는 코드

 

let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene
let topPadding = scene?.windows.first?.safeAreaInsets.top ?? .zero
let bottomPadding = scene?.windows.first?.safeAreaInsets.bottom ?? .zero

 

UIApplication을 통해서 top과 bottom의 safeAreaInsets을 구할 수 있다.

 

connectedScenes는 iOS 13부터 사용할 수 있다.

 

How can I get the safeAreaInsets i… | Apple Developer Forums

 

How can I get the safeAreaInsets i… | Apple Developer Forums

In the past, I use UIApplication.shared.windows.first?.safeAreaInsets.bottom to get the bottom safe area, but in iOS 15, there is an warning shows that windows has been deprecated. My project is written in SwiftUI, so is there a way to get the global safeA

forums.developer.apple.com

 

반응형