Animate UIView grow/shrink

animation, ios, iphone, uiview

Solution

After some tinkering I've managed to get the desired behavior by doing the following.

In the expand method, I use the UIView animation to alter the frame. In the shrink method, I use the UIView animation to alter the bounds and center.

I'm a little baffled as to why this works but trying to shrink with the frame does not. If anyone can share some insight into this that would be great.

Problem

I have a UILabel I want to animate growing and shrinking. While the size changes I need the bottom left corner to remain static so that it always appears directly above a bottom toolbar. I am using the following code to make the label grow: ``` [UIView animateWithDuration:kAnimationDuration delay:0.0 options:UIViewAnimationCurveEaseInOut animations:^{ CGFloat lblHeight = 42.0f; [label setFrame:CGRectMake(0.0, CGRectGetMaxY(self.view.bounds) - kBottomBarHeight - lblHeight, CGRectGetMaxX(self.view.bounds), lblHeight)]; } completion:^(BOOL finished) { }]; ``` and to make it shrink I use the same logic except that lblHeight is set to 17.0f The view correctly grows but when I try to shrink it the frame change animation is not animated. It blips into the new size and then animates into the new origin/location. I need the frame change to be animated. Can anyone see what I'm doing wrong?

Original source