[SWIFT] [iOS] Measures to prevent the expected operation of Status Bar height acquisition on iPhone12 mini

Event that occurred

--When I used status Bar height on iPhone12 mini to calculate the layout, the result was not as expected and the layout was misaligned.

environment

Xcode 12.3
Build version 12C33
Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28)
Target: x86_64-apple-darwin19.6.0

Verification

--I actually made a sample app and tried to display the values ​​obtained by the simulator.

iPhone12

iPhone12 mini

iPhoneSE 2nd

--It turned out that there is a difference between safe Area and status Bar height on iPhone12 mini. --Verification code t-osawa-009/StatusBarTest

Countermeasures

--Changed to use safeArea value for layout calculation

let height = navigationController?.view.safeAreaInsets.top ?? 
let height = view.safeAreaInsets.top

Summary

--Not statusBar height == safeAreaInsets.top. ――In the future, we recommend that you create a layout based on the safe Area.

Reference link

https://useyourloaf.com/blog/iphone-12-screen-sizes https://developer.apple.com/forums/thread/662466

Recommended Posts

[iOS] Measures to prevent the expected operation of Status Bar height acquisition on iPhone12 mini
[Swift UI] How to get the startup status of the application [iOS]
[Swift] Acquisition of IDFA on iOS14
[Ruby on Rails] Rails tutorial Chapter 14 Summary of how to implement the status feed