Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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).

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top