Reputation: 616
I've watched many Youtube videos on UIScrollView. Here, here and here. However nothing there is solving my issue.
Here I've a sample storyboard that I'm working with.
What I require:
BlueView
and CyanView
will adjust its height accordingly to screen size based on aspect ratio.YellowView
will have a variable height as it contains a ContainerView with embedded UITableView
or UICollectionView
. Meaning my users can switch between views to look at similar data, with different format. Its information is grabbed from server side. This means that if there is no content, it doesn't require any scrolling. If there are many rows of data to fetch, scrolling should work to display all my information.Problem faced
yellowView
and myScrollView
, the scrolling doesn't happen at all.Upvotes: 1
Views: 52
Reputation: 4222
Inside the UIScrollView
add a container View. That will contain rest of your views. So the heirarchy becomes like this:
|---UIScrollView
|----UIView
|---Blue View
|---Cyan View
|---Yellow View
This container view will have a leading, trailing and bottom and top to the UIScrollView
. Also add a equal width and equal height constraint to your UIViewController
s main view. Give a priority of 250
to the equal height constraint. And then:
UIView
which looks nice to you.Now your UITableView
will have a leading, trailing, bottom and top to the container view or just directly use a UITableView
.
If you wish to embed a UITableView
inside the yellow view or just use a UITableView
directly and expect the main UIScrollView
to be scrollable, you will have to manually get a height constraint outlet for your UITableView
and update it accordingly depending on the number of rows of the UITableView
and height of each row so that the yellow view
can increase its height based on the height of the embedded UITableView
and hence update the content view accordingly which will in turn update the total content size of the UIScrollView
.
Upvotes: 1