Bogdan Laukhin
Bogdan Laukhin

Reputation: 1454

Content in scroll view is shifted down with height value of navigation menu

I use view controller with embedded in navigation controller.

In this view I added scroll view and then content view inside scroll view

I added constrains for scroll view - zero for top, bottom, leading, and trailing. And the same for content view - zero for top, bottom, leading, and trailing. And I added width and height for content view the same as main view.

Inside content view I need to add different content (labels, text fields, buttons) - this will be settings screen with vertical scroll.

Now I see that content is always shifted down a bit (the same value as menu height)

How to make to located vertically on top?

And how to put all the content in the content view that should be vertically long and scrollable vertically?

enter image description here

enter image description here

enter image description here

Upvotes: 4

Views: 1725

Answers (6)

poroia
poroia

Reputation: 45

In iOS 11, automaticallyAdjustsScrollViewInsets is deprecated and adjusting UIScrollView's contentInsetAdjustmentBehavior is recommended instead.

This worked for me pretty well (Swift):

scrollView.contentInsetAdjustmentBehavior = .automatic

Upvotes: 0

Nimit Parekh
Nimit Parekh

Reputation: 16864

Go to your viewcontroller viewDidLoad method put following code.

self.automaticallyAdjustsScrollViewInsets=NO;

Upvotes: 0

Kunal Kumar
Kunal Kumar

Reputation: 1722

Just add this line to the viewDidload method of your ViewController.

self.automaticallyAdjustsScrollViewInsets = NO;

Upvotes: 2

Arun
Arun

Reputation: 644

Go to storyboard and select the appropriate viewcontroller and Uncheck AutomaticallyadjustScrollviewInsets.

Or

Go to viewdidload self.automaticallyAdjustsScrollViewInsets=NO;

Upvotes: 0

Badal Shah
Badal Shah

Reputation: 7602

I think you forget to remove tick -> Adjust scrollview insects .

enter image description here

Upvotes: 11

Sheereen S
Sheereen S

Reputation: 1236

Check you attribute inspector setting in Storyboard.Uncheck

adjustScrollViewInsets

from viewcontroller storyboard.Viewcontroller Storyboard settings.

enter image description here

Upvotes: 0

Related Questions