I got a UICollectionViewCell with an icon within it. I would like the cell to visually indicate that the user has tapped on it.

I'm trying UIView's animateWithDuration: and am trying to scale the icon's transform by 1.2 to make it larger, then set it to identity to make it original size. I've used such code before with regular images, and it seemed to work.

I get strange behavior where the image within a cell scales up, as if it is pinned by the top left corner. However, when it is scaling back to identity, it does so as if it scaling from the center (as you would expect it to behave). The result is that there's an unpleasant shift of the image center from one position to the next in between two animations.

How can I properly scale images within 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");
    }

}

没有正确的解决方案

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top