UICollectionView Growing/Shrinking Cells on Scroll - ios

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.

Related

How to scroll the UICollectionview from particular cell

I have a collection view. I need to scroll only cell4, cell5, cell 6 so on. First two cells are remain same. Is is possible using only UICollectionview. How to achieve this.
FYI: the height of the cell is more than the screen height.
One of options would be to subclass UICollectionViewLayout and update frames in attributes of first three cells every time when scroll offset changes. So the cells would look static.

Re-orderable custom collectionview layout

I sub-classed UIcollectionViewLayout to create my own layout. In the prepareLayout() method I create the frames for the attributes of each cell because I know where they should be. The frames for each cell are hardcoded. However, I can't hard-code the position of the frames because I want to be able to drag and drop cells. UICollectionViews have nice functions for that:
`collectionView.updateInteractiveMovementTargetPosition(_:position)`.
But this function can't change the location of the cells if their position is hard-coded.
Additionally if the cell is not in it's position it seems to disappear from the view. I want to dynamically change the position of a cell when I begin to drag it. Should I call invalidateLayout() somewhere? I have a UICollectionView as a subview of my UIViewcontroller.
So I've attached a longPress gesture recognizer to my collection view.
I faced this issue few months ago, you cant reload selected cells, the only way is reload whole Collection View. If you have any other solution, pls share me. Thanks

How to add UIScroller in UITableViewCell?

I have a table with different cells and I need to add a scroller view with special UI in some cells:
I need to develop the UI which you can see in section 0.
So my questions are:
How can I add a scroller view?
How can I load data only for those items which are shown right now?
How can I change the width of "Line" column after scrolling to the right?
I'll answer as best I can with some starting pointers for you...
You need to subclass UITableViewCell and in your subclasses drawRect method you should add a UIScrollView to the contentView.
Not totally sure what you mean here, please expand.
In your new table cell, set it as the delegate of the scroll view you implemented, then you''ll get callbacks when the scrollview scroll with the contentOffset value, which you can use to calculate how much to grow or shrink the line items.

UICollectionViewCells disappear when going out of UICollectionView frame

Consider the following:
I have a UICollectionView with a size of 400x400. This UICollectionView has 5 UICollectionViewCells which also have a size of 400x400.
Clip to bounds is set to false so that my UICollectionViewCells will be visible (this does not work, I can only see 1). I want this so I can use paging. When I start scrolling there are 2 cells, but when the scrolling snaps, the previous cell disappears and I can only see 1 cell.
I use dequeueReusableCellWithReuseIdentifier to retrieve cells to fill the collectionview. Can this be part of the problem?
How can I display the UICollectViewCells that are out of the collection view's frame?
You can't. What you describe for a problem is actually a feature of UICollectionView and UITableView. They reuse the cells that are not visible for performance and memory reasons. You might think of another approach like UICollectionView with custom layout if that would be possible for your requirement or directly use UIScrollView with paging and you rearrange all the views while is scrolling.

How to dynamically resize UITableViewCell based on UITableView scrolling?

I have tried looking for an answer to this question but so far I haven't got any luck.
Context
I have a UITableView inside a standard UIViewController (NOT a UITableViewController..). I have subclassed UITableViewCell and all the cells in the tableview are from the same class.
Requirement
I would like to find an efficient way to resize the cells based on the scrolling of the tableview. For example, when the cell is at the bottom of the visible list, the height is X. When the cell moves up on the screen, its height should proportionally increase to 2X.
Additional Info
I am close to just ditch the UITableView way and start making my own control that would implement such a feat by subclassing a UIScrollView. However, I would like to see if it is possible before going this path. I did see some very interesting SO posts but nothing that would put me on the right path.
Any hint or help would be highly appreciated.
You would need to respond to the scroll view delegate method scrollViewDidScroll: and implement it to record the cell at the top of the table view and reload the table view. Then your table view delegate method tableView:heightForRowAtIndexPath: sets the cell height by the relationship between the index path and the top cell index path.
Your main issue is performance while reloading the table view all the time.
If you wanted to roll your own solution it would be along the lines of the above description anyway, but you would be able to be more efficient than the table view as the table view will call the tableView:heightForRowAtIndexPath: method once for every row for every reload in order to calculate the total height of the table content.

Resources