4

I have a pretty complex app, that causes the safe areas on an iPhone X to be wrong (pushed down).

enter image description here

This screenshot is from a storyboard. It's a container view aligned to the bottom anchor of the Safe Area Layout Guide. Everything looks fine there and produces the correct result in an empty, new project.

But as soon as I instantiate and push the view controller in the original app, the result is this:

enter image description here

What could cause the safe areas to be distorted?

The property additionalSafeAreaInsets is definitely not set anywhere in the app. I've played around with a couple of other UIViewController properties, but nothing seems to change this.

Thanks!

Krunal
  • 68,602
  • 40
  • 230
  • 241
Alessandro
  • 219
  • 1
  • 3
  • 8
  • what code do you have for this view controller? how is it setup? – Scriptable Feb 13 '18 at 08:17
  • If you select your view controller in the storyboard and use the file inspector from the right hand panel. Do you have 'Use safe area layout guides' ticked? – Scriptable Feb 13 '18 at 08:19
  • No code is used to setup the view controller. It's instantiated strictly through UIStoryboard().instantiateViewController(withIdentifier:) – Alessandro Feb 13 '18 at 08:33
  • Yes, "Use safe area layout guides" is ticked, otherwise you wouldn't see the Safe Area on the left side. – Alessandro Feb 13 '18 at 08:35
  • I cannot see the left side :P – Scriptable Feb 13 '18 at 08:36
  • You can't? Where it says "Test Scene" with the view hierarchy, there's an entry there for Safe Area. Anyway, it's switched on :) – Alessandro Feb 13 '18 at 08:45
  • The top screenshot is your test project isn't it? not the project you are having issues on? check your constraints aren't going to superview and select safe area like in this other answer https://stackoverflow.com/questions/46708938/how-to-set-bottom-safe-area-to-xib-in-ios?rq=1 – Scriptable Feb 13 '18 at 08:47
  • No, both screenshots are from the original app, not the test project. – Alessandro Feb 13 '18 at 08:51

3 Answers3

0

Please share constraint layout view for your button to get proper/exact solution to your problem.

Here I had same problem.

enter image description here

I had added another view as a subview (gray view) in a main view and moved my button in it. I enabled the safe area layout guide for both main view and gray view.

enter image description here

Safe area layout for gray view safes my button inside safe area.

iPhone X, Layout Preview:

enter image description here

Hope this may help you!

Krunal
  • 68,602
  • 40
  • 230
  • 241
0
  • Click on the View(which contains your button) and then check Safe Area Layout Guide
JhanviR
  • 31
  • 3
0

So to perfectly answer my original question:

What could cause the safe areas to be distorted?

Turns out a totally different part of the app was modifying the size of the parent view controller's view.

Alessandro
  • 219
  • 1
  • 3
  • 8