Animate uicollectionview cells on selection

后端 未结 2 698
无人及你
无人及你 2021-01-14 17:49

I have created a customlayout and set my cells position attribute in layoutAttributesForItemAtIndexPath like this

attributes.center = CGPointMake         


        
2条回答
  •  余生分开走
    2021-01-14 18:13

    Maybe a different approach. Just override isSelected in the collectionViewCell.

     override var isHighlighted: Bool {
        didSet {
            if isHighlighted {
                UIView.animate(withDuration: 0.2, delay: 0, options: .curveEaseOut, animations: {
                    // animate highlight
                }, completion: nil)
            } else {
                UIView.animate(withDuration: 0.2, delay: 0, options: .curveEaseOut, animations: {
                    // animate unHighligh
                }, completion: nil)
            }
        }
    }
    

    In this post UICollectionView: Animate cell size change on selection you can see an example on how to animate a size change.

提交回复
热议问题