Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIScrollView in NavigationController ignores top layout guide

I've seen similar questions about custom transitions(iOS7 Custom ViewController transition and Top Layout Guide and Navigation controller top layout guide not honored with custom transition), but I have problem even with regular push. I'm using latest Xcode available now (Version 5.1.1 (5B1008)).

Here is my storyboard: storyboard Problem occurs in 3rd VC

Here is 3rd VC settings: enter image description here

My 3rd controller's layout is follows:

UIView
 UIScrollView
  InnerUIView
    Other views

I've tried two different ways to create a layout:

Ignore top layout guide (it has y = 64 because of nav bar)

I pinned scrollview's top to container (ignoring topLayoutGuide), manually set height of inner view and pinned its top to scrollView. It gave me the following result: enter image description here

Looks fine, but why do I need top layout guide then?

Use topLayout guide

ScrollView's top is pinned to topLayoutGuide. enter image description here

As you can see, top button moved down and view looks strange.

What is the right way of creating such layouts?

like image 349
user2786037 Avatar asked Dec 30 '25 23:12

user2786037


1 Answers

I had the same problem and spent hours pulling my hair out. My container view inside scrollview had weird top offset despite the fact that it had top constraint set. The workaround I've found - you have to uncheck Adjust Scroll View Insets in your controller layout options

enter image description here

that way content view (in my case) stays pinned to scrollview's top.

Unfortunately I couldn't find any reasonable explanation of this behaviour.

like image 191
ksh Avatar answered Jan 01 '26 13:01

ksh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!