I'm trying to replicate how the eBay iOS apps displays its images and allows users to expand each image larger.
Here's how it works:
eBay uses a UICollectionView
to display a list of images. When the user selects a cell, the cell expands with some buttons in the top. When the X is selected, the cell collapses back to original size.
How can I achieve something similar to this?
I've looked at questions UICollectionView Enlarge cell on selection and Expanding UICollectionView and its cell when tapped and tried implementing it with my own ideas.
One of the problems is I have AutoLayout design, and it's making this quite difficult.
Here's my storyboard:
I've tried this:
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
{
let cell = collectionView.cellForItem(at: indexPath)
cell?.superview?.bringSubview(toFront: cell!)
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: [], animations: ({
self.structureImageView.frame = CGRect(x: 0, y: 0, width: 375, height: 667)
collectionView.frame = self.structureImageView.bounds
cell?.frame = collectionView.bounds
self.separatorView.frame.origin.y = 667
self.structureInfoView.frame.origin.y = 667
}), completion: nil)
test = true
collectionView.reloadData()
}
var test = false
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize
{
if test == true
{
return CGSize(width: 375, height: 667)
}
return CGSize(width: cellWidth!, height: cellHeight!)
}
And the result:
Any assistance would greatly help!