UICollectionView Scrolling the ViewController - ios

Im trying to implement a CollectionView inside my viewController.
And it works just fine.
The problem Im having is that the CollectionView scrolls inside the Parent controller.
I wish to make that if you scroll the collection view - the whole view is scrolled and not just the collection view bit.
I tried disabling scrolling on the Collection View but then nothing is scrolling anymore.
So how would I go about setting the collection view, so that once you scroll on it the whole page scrolls and not just the collection view scrolling inside the parent view controller?

It should be simple, and you've done one right thing already.
Disable scrolling of your collectionView (or tableView, in the future just in case you'll use it, they're basically the same).
Add your collectionView (or tableView) inside a scrollView.
That scrollView is of course in your controller's view.
Make sure every constraints are set properly.
You might need to get the size of your collectionView (say height), and set that height value to the constraint height of your collectionView.
These answers of mine in the past should help you:
https://stackoverflow.com/a/52657995/3231194
https://stackoverflow.com/a/54211275/3231194
https://stackoverflow.com/a/53971539/3231194
Voila. The only scrolling enabled is your scrollView that contains your collectionView (or tableView).

Related

How to make a Horizontal and vertical scrolling TableView in iOS using storyboard?

here is my design structure
I was wondering about creating a horizontal and vertical scrolling tableview. I have tried a tableview inside a scrollview but I failed miserably. What to do?
I use swift4 but I wanted to do in storyboard.
The nature of content is like an excel sheet with lots of horizontal and vertical scrolling rows and columns of data.
Actually you can do this using a hack. Put the tableView inside a scrollView. Then you should give a dynamic width to the tableView by specifying a width in storyboard for tableView or any child view of that scrollView(So we get the horizontal scrolling).You have to adjust some constraints depending on your requirement
Mine worked fine but as many users have said try a collection View if its easy
Note. There is a default scrollView within a tableView, So adjust your height of tableView in a way so the scrollView of tableView work and not the parent scrollView, while scrolling from top to bottom
Instead of using TableView try using collection view, there you can use horizontal and vertical scrolling using storyboard?
Try to use collectionview instead of tableview.
If your requirement demands use of tableview anyhow, then you can use tableview within scrollview.
In tableview within scrollview approach, you need to distinguish your parent scrollview as well as tableview's scrollview. Try to differentiate parent scrollview and tableview's scrollview with different tags. Because both scrollview will call delegate methods of viewcontroller, if implemented. Just check tag of scrollview in all delegate methods of scrollview and perform action accordingly.
As per my understaing you want a view which you want vertical scroll view and horizontal inside it.
So here my suggestion is to use UITABLEVIEW for vertical scrolling and UICOLLECTIONVIEW for horizontal scrolling inside tableview
Both will work fine

Swift: Did Tumblr add a UICollectionView in a UIScrollView?

I've been trying to replicate this effect for a couple days which was inspired by Tumblr.
I've previously asked questions on here with different approaches of the same problem but to no avail. I'm just curious as to how the engineers at Tumblr created a horizontal collection view, with two vertical collection views, and is able to scroll down without affecting the view above (without resetting the position of the view when you scroll vertically in a different tab).
Header Views
I tried this, but the header view was isolated and I had to scroll to the right to see the collectionView cells. This did not work.
Changing the topLayoutConstraint constant of my UIView (not cv header) with respect to the contentOffSet of the vertical collectionView.
This almost got the effect I wanted, except that when I scrolled horizontally, there was a huge gap between my collection view and if I scrolled in that new tab, the UIView would appear again because, again, topLayoutConstraint gets scrolled up depending on the contentOffSet of my vertical collectionView contentOffset.
Changing the position of the UICollectionView frame, and scrolling the super view up simultaneously with NSNotificationCenter.
Alas, this method did the same as method #2, except that the vertical collection view cells scrolled faster than the super view.
I ran out of options to make this work so I will show you in detail what's attempted to be replicated (also note the scroll bar on the right):
Note when I scroll down the first tab. I switch, and then scroll down further. Originally, as I've said, there would be a gap between the second main CV, and when I scrolled, the view would reposition as if were scrolling up again. On here, the view on top keeps going up. So I'm curious as to what method Tumblr engineers used to do this. UICollectionView inside UIScrollView? Other suggestions?
I believe there is no UICollectionView involved. It looks like UIPageViewController and each its page is a UITableView.
Perhaps the UIPageViewController sits in a UITableView as well - the header also moves up when you scroll. This main table has only one cell (and a header) which is occupied by the UIPageViewController.
Hope it helps.

UITableView not scrolling inside of UIScrollView

in my view controller I have a ScrollView for content adaptation on various devices .. I need to insert a tableView inside the ScrollView but I noticed that my tableView not scrolling when it is inside a ScrollView. Can someone help me figure out how to fix this?
If you want your table view to scroll set the content size of scroll view less than that of your table view.

Scrolling up UICollectionView don't move a UIView above it

I am working in a profile ViewController. This profile has a main image in a UIView subclass and a CollectionView gallery with some images. I would like to be able to scroll up the UICollectionView and move the UIView too, and if I scroll down, I want to watch again the UIView when the collectionView first item is showed again.
I have tried to do this adding the collectionView and the UIView to a ScrollView, but the UIView only scroll up if I touch it.
In this picture you can see my problem
Thank you in advance
You need to make the view at the top a Header View of the collection view.
Essentially it needs to be an actual part of the collection view if you want this action. (That's the easiest way anyway).
So the collection view will take up the whole screen but it will have a header view. Then when you scroll the collection view the header will move out of view and then come back in when you scroll down again.

ios : tableview not appearing in subview of a scrollview

I have a scrollview with multiple views.Enabled horizontal scrolling.Each view contains a tableview.I have page control in scrollview. when i drag horizontally, the views are appearing without tableview except the first view. Please give me suggestions.
Make sure if setContentSize to your scrollview means scrollview content size is the size of your main view.
When you scroll to next view or if you scroll to view displayed for first time, make sure you reload table. You can implement his through delegate and protocols. For example, when you scroll to second view for first time, then controller should call some method on subview to reload its table.

Resources