关于UICollectionView的cell被选中时的小动画--缩小一下再恢复

此小动画主要实现的是点击cell的时候,让cell缩放一下再恢复原来的样子。
我们可以在-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath实现 。

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    RYCollectionCell * cell = (RYCollectionCell *)[collectionView cellForItemAtIndexPath:indexPath];
    if (cell) {
        [UIView animateWithDuration:0.1 animations:^{
            cell.transform = CGAffineTransformMakeScale(0.8, 0.8);
        } completion:^(BOOL finished) {
            [UIView animateWithDuration:0.1 animations:^{
                cell.transform = CGAffineTransformMakeScale(1.0, 1.0);
            } completion:^(BOOL finished) {
                //这里实现点击cell后要实现的内容
                }
            }];
        }];
    }
}

(1)animateWithDuration 设置动画的时间。
(2)CGAffineTransformMakeScale(CGFloat sx, CGFloat sy)(缩放:设置缩放比例。
(3)transform我们一般称为形变属性,其本质是通过矩阵变化改变控件的大小、位置、角度等。iOS提供的三个方法分别:CGAffineTransformMakeRotation(旋转)、CGAffineTransformMakeScale(缩放)、CGAffineTransformMakeTranslation(移动)。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容