2

Is it possible to tween a variable (let's say a float from 0.0 to 2.0 over a period of time) in objective-C? Something like what TweenMax would do in flash. I guess the class methods of UIView don't do that. Is it doable maybe with CoreAnimation? Or would someone have to use NSTimer?

Thanks

4

3 回答 3

2

Use an NSTimer on a selector that increments a member variable from its start value of 0.0 by the increment value.

When the variable reaches the end point (2.0), invalidate the NSTimer instance to finish incrementing.

See the documentation for more information about the method to use.

于 2009-08-26T10:04:07.000 回答
2

What are you doing? If you are trying to animate something then you can use CA and it will deal with calculating the intermediary values over time.

If you are trying to do for something not related to views or animation you will need to do it yourself (using a timer, or a custom property implementation that dynamically calculates the value based on the current times when it is accessed).

于 2009-08-26T13:11:20.857 回答
1

I've been working on putting something of a framework together recently, part of which is a 'tweener'.

I'm still pretty new to obj c, but so far it seems to be serving my purposes reasonably well. Feel free to have a peek/play!

ShinobiTweener v0.1 for Objective-C

于 2011-01-01T22:31:36.507 回答