Scroll Multiple CollectionViews simultaneously - ios

I have a tableView with 20 tableViewCells and within each cell I insert a collectionView (with 100 cells) which scrolls horizontally. I would like to scroll ALL collectionViews when any of the collectionViews is scrolled.
Implementation
I have subclassed the collectionView and have overridden scrollView delegates.
I have currently gotten this to work with the following approaches:
When ANY CollectionView is scrolled, I get all visible tableViewCells and grab the collectionsViews within each cell and set the collectionView contentOffsets iteratively or by using makeObjectsPerformSelector.
Had a CGPoint property with an observer which triggers when the property changes; then inside the collectionView subclass scrollViewDidScroll: I set the property, this will trigger the observer and set the collectionView accordingly. (the collectionView contentOffset is set inside observeValueForKeyPath:ofObject:change:context:)
I have also used NSNotificationCenter to broadcast any scroll and in-turn scroll every other listener
The problem I face is that the collectionViews scrolls are a bit glitch sometimes especially when the scroll is coming to a halt. currently there is no data in collectionView cells but it glitches.
Please does anyone know of a way to simultaneously scroll multiple collectionViews without glitches.
Thanks in advance.

Related

Dynamically update uicollectionview cell height

I am working on a quite complicated case
I have a nested UICollectionView
The outer UICollectionView A is for vertical scrolling,
and it's the first cell, is UICollectionView B, for horizontal scrolling.
It has been implemented perfectly, but now there is one more requirement
When scrolling the first cell to the second page, there is one more banner appeared on the bottom of the first cell.
Therefore I need to update the height of cell when scrolling.
If I try to call invalid layout when scrolling, it will be very low efficient. Are there any more methods to support it?
Solved.
First after received the data from the server, each cell height will be calculated and [collectionview reload] will be called.
Then after layouting the collectionview, the size for each cell is cached according to the indexpath.
To implement the 'realtime' resizing, the gesture will call a resizing function directing through a delegate, and directly modify the size cache and call [collectionview.layout invalidlayout].
It looks smooth.

dynamic, custom layout UICollectionView embedded in UITableViewCell

I have UITableViewController with 1 section and header with UISegmentedControl inside.
If user presses first segment we should display UITableView cells
If user presses second segment we should display custom vertical scrolling collection grid with collection items below that header
possible solutions:
change UITableViewController to UICollectionViewController, and UITableViewCells to UICollectionViewCells. This should work but I'm trying to avoid this solution
UICollectionView embedded in UITableViewCell. Setting UICollectionView scrolling enabled to false, adjusting UITableViewCell's height to fit entire UICollectionView's contentSize.height. In systemLayoutSizeFitting(...) method of container (UITableViewCell) we call layoutIfNeeded on container and on contained UICollectionView and return UICollectionView's contentSize.
problem:
(re)calculation of entire UICollectionView contentSize requires a lot of work if we have hundreds of items (cellForItemAtIndexPath for every item). Want to avoid this somehow. Maybe we can increase container (UITableViewCell) height during scrolling UICollectionView which is embedded inside.
Same as 2 but we have fixed size container UITableViewCell (same height as view without header) with UICollectionView inside. When we scroll UITableView to the very bottom UICollectionView scroll should continue scrolling.
problem:
I don't understand how to deal with 2 instances of UIScrollView with scrollingEnabled = true for both. I think this could be solved with pan gesture recognizer delegates. If it is so I need help here.
I would personally opt for number 1 and completely avoid number 2. For number 3, you could set tableView.scrollingEnabled = false when the second segment is tapped. Set it to true when the first segment is tapped. That way, when it's false, the UICollectionView in your UITableViewCell can still scroll.
This tutorial may help with putting a UICollectionView in a UITableViewCell.

UICollectionView Growing/Shrinking Cells on Scroll

I'm trying to make each cell grow/shrink if it becomes active/inactive in a horizontal collection view as the user scrolls it. I tried a few methods such as a custom UICollectionViewFlowLayout subclass with an overridden prepareLayout() but I'm having trouble getting the cell to grow with a nice animation.
Does anyone have sample code to make cells grow while scrolling a collection? Thanks so much for any help.

UIScrollView in Custom UITableViewCell mixing up data

I have a UIScrollView in each UITableViewCell of my table view that lays out UIViews horizontally - kind of like the "Featured" section on Apple's App Store. When I'm setting up the UITableViewCell I call a function within the custom UITableViewCell to layout the scroll view. This loops through data assigned to that tableview cell's index path and then creates the custom views and adds them to the scroll view. However, these get mixed up when scrolling the tableview and when the tableview refreshes.
If I clear the subviews before laying them out, it does work. However, I'd like to keep the scroll position at the same point every time it shows the cells. How is this possible?
I've just added an external array that stores the current offset for each scrollview, and then manually set the offset on each scrollview everytime the tableview gets refreshed.

How to manage screen scrollview and collectionview scrollview same time in ios/xamarin.ios

On one screen,I am having some content and below that having collectionview,so I want to know how to manage scrollview of screen and scroll of collectionview.I cant make disable collectionview scroll bcoz I am using paging for collectionview on DecelerationEnded delegate method,So for that I ahve to use scroll of collectionview.
So,please give me solution that how to mange these two scrollview same time because screen is not responsing for two seconds.
You can put tag(self.scrollView.tag = XXX) for the scroll view and put conditions in the delegate methods.

Resources