简体   繁体   English

如何在uicollectionview中放大单元格的内容

[英]How to zoom in the content of cell in uicollectionview

在此处输入图片说明

In the above image,A,B,C,D,E are each custom cell,of collection view and i want to zoom in the cell one by one like c cell. 在上图中,A,B,C,D,E是集合视图的每个自定义单元格,我想像c单元格一样逐一放大该单元格。

Any suggestion? 有什么建议吗?

Just call this method when your collectionviewcell click 当您的collectionviewcell单击时,只需调用此方法

[self animateZoomforCell:cell]; // pass cell as collectionviewcell

-(void)animateZoomforCell:(UICollectionViewCell*)zoomCell
{
    [UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{

        zoomCell.transform = CGAffineTransformMakeScale(1.6,1.6);
    } completion:^(BOOL finished){
    }];
}
-(void)animateZoomforCellremove:(UICollectionViewCell*)zoomCell
{
    [UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{

        zoomCell.transform = CGAffineTransformMakeScale(1.0,1.0);
    } completion:^(BOOL finished){
    }];
}

In swift 3 based on Himanshu Moradiya solution: 在基于Himanshu Moradiya解决方案的Swift 3中:

 func animateZoomforCell(zoomCell : UICollectionViewCell)
{
    UIView.animate(
        withDuration: 0.2,
        delay: 0,
        options: UIViewAnimationOptions.curveEaseOut,
        animations: {
                        zoomCell.transform = CGAffineTransform.init(scaleX: 1.2, y: 1.2)
            },
    completion: nil)
}
func animateZoomforCellremove(zoomCell : UICollectionViewCell)
{
    UIView.animate(
        withDuration: 0.2,
        delay: 0,
        options: UIViewAnimationOptions.curveEaseOut,
        animations: {
            zoomCell.transform = CGAffineTransform.init(scaleX: 1.0, y: 1.0)
    },
        completion: nil)

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM