I'm trying to replicate this behaviour. First thing is the ease in out cells scroll. I made a similar behaviour, but only when cells are not displayed and are going to be displayed. I'm trying to have that behaviour on cells that are on screen. I should probably do this on some UIScrollView
Delegate, but i'm in need of some guidance.
class ViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout {
var array: [Holiday] = [Holiday(imageName: "a"),
Holiday(imageName: "b"),
Holiday(imageName: "c"),
Holiday(imageName: "d"),
Holiday(imageName: "e"),
Holiday(imageName: "f"),
Holiday(imageName: "g"),
Holiday(imageName: "h"),
Holiday(imageName: "i")]
override func viewDidLoad() {
super.viewDidLoad()
self.collectionView.backgroundColor = .white
self.collectionView.register(CollectionCell.self)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: view.frame.width, height: 176)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return 0
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
return collectionView.reusableCell(for: indexPath, with: self.array[indexPath.row]) as CollectionCell
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.array.count
}
override func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
cell.transform = CGAffineTransform(translationX: 0, y: cell.frame.height/2)
UIView.animate(withDuration: 0.5, delay: 0.01 * Double(indexPath.row), options: [.curveEaseInOut], animations: {
cell.transform = CGAffineTransform(translationX: 0, y: 0)
}, completion: nil)
}
}
For this behavior you need to use UIDynamicAnimator
and UICollectionViewFlowLayout
Take a look at this example, maybe it will help you: https://www.cocoacontrols.com/controls/thspringycollectionview