user3369214
user3369214

Reputation: 431

IOS : Make entire view scrollable, not only subview

I have a viewController in which I have a scrollView in which I have 3 views. This is a scheme :

The main problem is that, in my container (in which there is a view controller), I have a collectionView (which can scroll) but I want my entire scrollView to scroll (not only my container).

So this is what I have :

Only the Container is scrolling

And this is what I want : I want the entire scrollView to scroll

Anyone can help me with this ?

Upvotes: 1

Views: 3573

Answers (4)

nodox
nodox

Reputation: 393

I just solved this problem for my own project. Assuming you are using storyboards, I made the UIView a child of UITableView and made the UITableView extend the full viewport of the device.

Since UITableView implements UIScrollView you get full screen scrolling of your content.

General Rule your parent view has to implement UIScrollView and extend the full screen to get viewport vertical scrolling.

Hierarchy of TableView

Upvotes: 1

iphondroid
iphondroid

Reputation: 500

A scrollview will scroll only if its contents are bigger than its frame. This applies to the parent scrollview as well as the child scrollview. Here in your case, for the parent scrollview to scroll its contents (Header, Tabbar & container) together must have greater height than its parent. The child scrollview (container) is already scrolling because its contents (a view controller) has greater height than its parent.

I have made both scroll views to scroll:

(1) The parent scrollview - by increasing the height of the child scrollview so that it extends below the main view controller's frame. The child scrollview is one of the contents of the main scrollview.

(2) The child scrollview - Setting a large content inside it so that it is bigger than its parent. I have used a long UIImage as its content.

Also, I have used autolayout and pinned the contents to the scrollviews' sides by adding constraints.

Hope this helps.

This is how it scrolls: Scrolling of UIScrollView inside another

Upvotes: 0

Fábio Salata
Fábio Salata

Reputation: 372

You should set the frame of the container view to match the height of the view controller that it is loaded in it and set the contentsize of the scroolview based on the container height.

Upvotes: 0

Zell B.
Zell B.

Reputation: 10286

To do this, if you are not using auto layout or if you are adding views to container programmatically, you must manually set collection view frame to match its content size after you load some data on it. If you are using auto layout, you should create height constraint outlet and set its constant value based on collection view content size, again after loading data on it

Upvotes: 0

Related Questions