Avatar ·

How to get the height of the top and bottom Safe Area insets (safeAreaInsets) in iOS?

Hello, colleagues! I am developing an iOS app in Swift and encountered a problem: I need to programmatically get the exact values of the top and bottom Safe Area insets (for example, to account for the status bar height and the "notch" on iPhone X and newer, as well as the bottom Home Indicator bar). \n\nI tried using `view.safeAreaInsets.top` and `view.safeAreaInsets.bottom` in the `viewDidLoad()` method, but these values return 0. I read that this happens because the Safe Area is not yet formed at the time the view loads. As a workaround, I tried calling this code in `viewDidLayoutSubviews()`, but there I get strange values — for example, `top` equals 44 and `bottom` equals 34, although on iPhone 14 Pro Max it should be 59 and 34 respectively (taking into account the Dynamic Island). \n\nHere is my current