Dimitris
Dimitris

Reputation: 13680

Tween a value in iPhone objective-C

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

Upvotes: 2

Views: 2423

Answers (3)

lznpde
lznpde

Reputation: 11

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

Upvotes: 1

Louis Gerbarg
Louis Gerbarg

Reputation: 43452

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

Upvotes: 2

Alex Reynolds
Alex Reynolds

Reputation: 96976

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.

Upvotes: 2

Related Questions