Creating a swiping card stack with UICollectionView and UICollectionViewCells?

被刻印的时光 ゝ 提交于 2020-01-16 02:05:10

问题


So far, I made my collection views which scroll horizontally in either left or right.I added UICollectionViewCells into one UICollectionView. My problem that I'm having is trying to find the right settings to make the cards stack on top of the first card, as demonstrated in the photo below.

Here are the settings for my collectionView and how it displays its cells.

lazy var collectionView: UICollectionView = {
   let layout = UICollectionViewFlowLayout()
    layout.scrollDirection = .Horizontal
    layout.minimumInteritemSpacing = 0
    layout.minimumLineSpacing = 78
    let cv = UICollectionView(frame: .zero, collectionViewLayout: layout)
    cv.backgroundColor = UIColor.clearColor()
    cv.showsHorizontalScrollIndicator = false
    cv.translatesAutoresizingMaskIntoConstraints = false
    return cv

}()

回答1:


You're going to have to subclass UICollectionViewLayout, set the UICollectionViewLayoutAttributes for each cell, and make sure to set zIndex to the indexPath.row of the item in order to get overlapping. You can take a look at my sample project on GitHub that implements something very similar.

There are some bugs in UICollectionViewLayout related to animating insertions of new cells when the cells are overlapping (which is why I made the sample project in the first place).



来源:https://stackoverflow.com/questions/38084777/creating-a-swiping-card-stack-with-uicollectionview-and-uicollectionviewcells

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!