0
votes

I use the following lines of code:

[UIView animateWithDuration:0.50
    animations:^{ itemView.transform = CGAffineTransformIdentity; }
    completion:^(BOOL finished) { if (finished) [itemView removeFromSuperview]; }];

The animation does nothing. If I take the removeFromSuperview out of the completion block, it doesn't work either, I guess because the view is removed before it completes. So, either way, the appearance is the same - no animation.

I'll appreciate any suggestion or workaround on this.

1
are you sure itemView.transform is not identity before the animation? - maroux
CGAffineTransformIdentity is a transform with no change to either scale, rotation or translation. This means that unless the itemView has a transform before the animation you will animate to and from the same transform. Are you sure this is what you want? - David Rönnqvist
It's unclear what you want to achieve, and what exactly happens instead. Please clarify. Does "the animation does nothing" mean nothing changes, and then after half a second the view vanishes? Because that's exactly what you've defined (if your view didn't have a different transformation applied before). - fzwo
Thanks for your replies. See below. I was thinking I had already done a transform and was trying to undo it. It was a dumb question. - RegularExpression

1 Answers

0
votes

Are you setting the transform correctly? The below is an example of scaling a UIView to zero area and then removing it from the superview.

UIView *itemView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 200, 200)];
[itemView setBackgroundColor:[UIColor redColor]];
[self.view addSubview:itemView];

CGAffineTransform trans = CGAffineTransformScale(self.view.transform, 0, 0);
[UIView animateWithDuration:2.5 delay:0 options:0 animations:^{
    itemView.transform = trans;
} completion:^(BOOL finished) {
    [itemView removeFromSuperview];
}];