简体   繁体   中英

UIView Animation iPhone (obtaining information on the frame dynamically)

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 (ie 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.

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

See Key-Value Observing.

我对此进行了调查,似乎无法在UIView动画过程中获取正在动画的组件状态的更新。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM