views:

291

answers:

3

I have a UIView called goalBar which is being animated by increasing the size of the frame according to a float value called destination:

CGRect goalBarRect = CGRectMake(0, 0, destination, 29);

[UIView beginAnimations:@"goal" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:2.0f];

goalBar.frame = goalBarRect;

[UIView commitAnimations];

The animation works perfectly and the rectangular view increases its width over the course of the animation (from 0 to the value for destination).

However, I wish to be able to extract the values for the frame of the UIView being animated (i.e. goalBar) as the animation takes place. By that I mean that I wish to place the value of the width for the animated frame in a separate UILabel so that the user sees a counter that provides the width of the UIView as it's being animated.

Any help on how to do the above would be gratefully received.

A: 

How about observing the frame property of the view. So that you get callbacks when it changes.

See Key-Value Observing.

St3fan
The notification is only given at the end of the animation. What I really need is a runing commentary on the size of the frame as it is expanding (i.e. during the animation).
Urizen
A: 

I've looked into this and it seems that it is not possible to get updates on the state of the components being animated during the UIView animation process.

Urizen
A: 

You can make it possible! If you make the animation yourself, the old-fashioned-way. Make something like Brad says HERE, and write the increasing variable to your UILabel. Credit goes to Brad.

John Kofod