views:

79

answers:

1

I came across issue where I need to animate height change of UILabel frame or its enclosing view's frame. Label is multiline.

The issue is that given with large text which does not fit initially into label(say it takes 3 lines), then animating the label's height to increase, immediately changing 3 line to 4 and then animating the frame increase.

Opposite effect is when the text fully fit into label(4 lines), then I animate height decrease, 4 lines are instantly becoming 3 and only then I see animating frame size decrease.

This is of course not good for an eye.

What I expect is something like keep the label's origin.y intact and then as frame is increasing the more text is revealing from the bottom. The ellipsis may convert to missing word instantly, that is not a problem.

A: 

If you want to keep origin.y intact then you have to animate it with CoreAnimation stuff. Set once:

label.layer.anchorPoint = CGPointMake(0,0); //I believe 0,0 is the upper left or it was 0,1?

after doing this you just need to change the size accordinly:

I would measure the text first (With NSString's methods)and see if the label needs to be resized. In case it needs to then adjust label.numberOfLines and label.layer.bounds = CGRectMake(label.layer.bounds.origin.x,label.layer.bounds.origin.y, label.layer.size.width, newHeight);

This should work

I hope this helps.

nacho4d