Kodeco Forums

Swift Expanding Cells in iOS Collection Views

Learn how to make expanding cells as in the Ultravisual app in this tutorial on collection views.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/1709-swift-expanding-cells-in-ios-collection-views

Thank you for this tutorial Chris. What other resources do you recommend for learning more about design in iOS? I’d like to make more apps that are nice to look at and fun to interact with while still being functional (i.e. presenting some content or service other than nice looking transitions).

Nice tutorial. Can you please let me know how to achieve the animation without overlapping of images. It should shrink from bottom and expand from top part of the cell. It should not overlap each other like stack. I tried with many ways using this tutorial but unable to achieve.

Thanks for the great tutorial. How can make this to show the featured cell in the bottom instead of top. I want replicate this functionality to show the bottom cell as feature but unable to figure out the frames for the cells in prepare layout, calculating featuredItemIndex and calculating scroll offset to stop on the last visible cell.

In iOS 10 with Swift 3 the layout seems to be broken. Does anyone have an idea why that is? Thanks

Have you been able to get the solution working for iOS 10 with Swift 3.0!?

It’s because of the prefetching feature of UICollectionView in iOS 10. This restores the previous behaviour for now:

if #available(iOS 10.0, *) {
    collectionView!.isPrefetchingEnabled = false
}
2 Likes

Thanks for your reply!

Thank you for this tutorial, Chris. I need a small help. I want to scroll at particular indexPath but It’s not working.

collectionView!.scrollToItemAtIndexPath(NSIndexPath(forItem: 6, inSection: 0), atScrollPosition: .Top, animated: true)

I have used this code but It’s not working.If I am using the wrong syntax or is there any extra code is required for that.

Where does this fix go? I’m now crashing after converting to Swift 2.3 at cellForItemAtIndexPath when I scroll.

Thanks,
Dave

Has anyone tried adding a navigation bar to collectionview controller with the ultravisual layout? There seems to be some sort of error where the search bar is not clickable. Bar button items on the navigation bar work fine, but the embedded search doesnt seem to work at all and is unclickable.

can you show the code.

Have you found a solution?

Did you manage to make it work?

Is there an up to date tutorial?

Is there anyway (or has anyone already done so) to add a section footer at the end of the collection view!? It doesn’t allow for the option to Enabled Section Header in the Attributes Inspector of the Storyboard!?

Please find the tutorial in Latest Swift syntax here:
https://github.com/VamshiIITBHU14/ExpandingCollectionView

Any idea how I can hook up buttons to the cell elements? That whenever I would press on one of the cells, there would be a new view with more details about the cell that just got pressed?

I am new in swift. I have downloaded the final project and the list shows duplicate images at the same location.

When converted into swift3 it shows error in UltravisualLayout.swift.
The problem resolved by changing the method signature to
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]?

Then I have to override another function in UltravisualLayout.swift

override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes?{
    return cache[indexPath.item]
}

But now it shows duplicate elements in list.
Maybe I have to work with override func prepare() function

This tutorial is more than six months old, so questions are no longer supported at the moment for it. We will update it as soon as possible. Thank you! :]