On an iPad, my view controller (inside a navigation controller, as the detail view of a split view controller) has a topLayoutGuide length of 64 with the navigation bar shown and 20 with the navigation bar hidden. This makes sense.
On an iPhone in landscape, the status bar is automatically hidden and the navigation bar gets shorter. The topLayoutGuide length reads as 32 with the nav bar shown, and 0 with it hidden. This also makes sense.
However, on an iPhone in portrait, it has topLayoutGuide lengths of 44 with the nav bar shown and 0 with it hidden. The status bar is shown automatically; why doesn't the topLayoutGuide acknowledge that extra 20px of space?
I'd rather not write obnoxious conditional code just so the iPhone will read its topLayoutGuide correctly. Is there a property of the view or navigation controller that I can set that will return the intuitive values for topLayoutGuide? And does it have something to do with being inside a split view controller?
It should not like this. toplayout guide should always remains same in both ipad and iphone. Check twice if you are making any mistakes in count.
You can do one experiment : drag one view in VC(without nav bar) and positon it at
y=20
and then click on pin and check top of it by clicking dropdown arrow it will shows distance from toplayout guide by default.See the screenshot of it :
Now if you pin this constraint and then open in
iphone or ipad
it will remains exact above status bar means 20 pixel below from view's edge.You have set constrains with
0 distance (constant = 0)
with top layout guide so it maintain0 distance with layout guide
and so it's looks 20 pixel below from edge.Now if toplayout guide becoming 0 (as you said in question) then this view should touch to edge because it's manage 0 distance with top layout guide. and your layout guide is zero so view should touch edge or it's y should be 0 but it is not happening so that I can say that you are making some wrong calculation
Hope this will help :)