1

我有一个 UICollectionViewCell 里面有一个图标。我希望单元格能够直观地表明用户已经点击了它。

我正在尝试UIView's animateWithDuration:将图标的变换缩放 1.2 以使其更大,然后将其设置为标识以使其成为原始大小。我以前在常规图像上使用过这样的代码,它似乎工作。

我得到奇怪的行为,其中单元格内的图像按比例放大,就好像它被左上角固定一样。但是,当它缩小到同一性时,它会像从中心缩放一样(正如您所期望的那样)。结果是图像中心在两个动画之间从一个位置到下一个位置发生了令人不快的移动。

如何在 UICollectionViewCells 中正确缩放图像?

-(void)setSelected:(BOOL)selected
{

    [super setSelected:selected];
    if(selected)
    {
        //I tried this, does not seem to do anything
        self.icon.layer.anchorPoint = CGPointMake(0.5, 0.5);

        [UIView animateWithDuration:0.3 animations:^{
            self.icon.transform = CGAffineTransformMakeScale(1.2, 1.2);

        } completion:^(BOOL finished) {

            [UIView animateWithDuration:0.4 animations:^{
                self.icon.transform = CGAffineTransformIdentity;
            }];
        }];

       DLog(@"selected");
    }else
    {
        DLog(@"unselected");
    }

}
4

0 回答 0