Animate uicollectionview cells on selection

痞子三分冷 提交于 2019-11-29 11:30:22

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.

lineofcocoa

I'm animating the attributes by using didSelectItemAtIndexPath in my UICollectionViewDelegate:

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    [_collectionView.collectionViewLayout invalidateLayout];
    UICollectionViewLayoutAttributes *newAttributes = [_collectionView layoutAttributesForItemAtIndexPath:indexPath];

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