Search code examples
iosswiftautolayout

Is the safe area in iOS strictly enforced by the operating system?


I'm rather new to iOS programming. But I am wondering what will happen if I intentionally create view layout constraints that violate the safe area layout guidelines. Will the iOS operating system still respect them?

Will iOS simply quietly shift all my offending constraints from view.topAnchor to view.safeAreaLayoutGuide.topAnchor? Or maybe, even worse, my constraints will simply be ignored altogether?


Solution

  • All of these are guidelines for you to follow for your app to be a good iOS citizen. These are not enforced at run time.

    It's your choice to use the guidelines that best fit your app's content. For example -

    1. UIImageView instances, specially when used as backgrounds, are usually expected to cover the screen end-to-end extending under the safeArea like statusBar etc.
    2. Main app content like titles, lists etc. are expected to stay clear of safeArea to be readable/scannable easily.

    Will iOS simply quietly shift all my offending constraints from view.topAnchor to view.safeAreaLayoutGuide.topAnchor?

    iOS will respect what you asked, it will not automatically shift anchors quietly.

    Or maybe, even worse, my constraints will simply be ignored altogether?

    No, it won't.