macOS, iOS
[SwiftUI] bottom notch height 받아오기
SweetDev
2021. 3. 29. 20:06
sceneDelegate에서 받아와서, public으로 저장하고 쓰고 있당
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
// Create the SwiftUI view that provides the window contents.
let contentView =
TabViewScene()
// SNSLoginScene()
// Use a UIHostingController as window root view controller.
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.rootViewController = UIHostingController(rootView: contentView)
safeTop = window.safeAreaInsets.top
safeBottom = window.safeAreaInsets.bottom
self.window = window
window.makeKeyAndVisible()
}
...
Constant.swift
public var safeTop: CGFloat = 0.0
public var safeBottom: CGFloat = 0.0