TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Dec 2014 |
Maintained by Garrit Schaap.
A Tweening Library for Objective-C
GSTween is now available via Cocoapods!
The documentation is currently being created and will be updated constantly as required.
The instructions will be added soon.
As a first simple example, we want to tween the frame-value of a UIView
to CGRectMake(0, 0, 320, 568)
with a bouncing ease out.
Add this import to the top of your file (We need to import the GSTween and the easing we want to use, or we can import all easing header files):
//import GSTween
#import <GSTween/GSTween.h>
//import all easing header files
#import <GSTween/Easings.h>
Create a GSTween Object to create and instantly run the animation:
[GSTween tweenWithTarget:self time:3.0f ease:[Bounce easeOut] params:@{ @"frame": @"{{0,0},{320,568}}" }];
In this case we create a tween inside a UIView
. We set the target to self, the animation time to 3 seconds and adding a bouncing ease out. Next we set the parameters in the NSDictionary
. We want to tween the property frame, so we name the key of the dictionary the same and than we add the value we want to tween to. What you see in this example is the string representation for a CGRect.
Currently you can tween any property that is not readonly of the type CGFloat
, NSInteger
, CGRect
, CGSize
or CGPoint
. If GSTween don't find the property on the target, it will throw you a warning in the log.
Here are some examples how to write the values into the dictionary:
@{ "floatValue": @4.2f };
@{ "integerValue": @42 };
@{ "rectValue": @"{{100, 100}, {200, 200}}" };
@{ @"sizeValue": @"{100, 100}" };
@{ @"pointValue": @"{42, 42}" };
And as a bonus, you can tween as many values as you want in one tween-object:
[GSTween tweenWithTarget:self time:3.0f ease:[Bounce easeOut] params:@{ @"frame": @"{{0,0},{320,568}}", @"floatValue": @4.2f, @"integerValue": @42 }];
There are some special properties to use: x
, y
, width
, height
, frameOrigin
, frameSize
. If you have a UIView
and you have no property named like one of these, GSTween will automatically create a tween of the frame property for you, otherwise it will tween your property as you would expect.
You can choose between the following easings:
The easings based on the equations of Robert Penner and they are licensed under the BSD License. For more information, go here: http://www.robertpenner.com/easing_terms_of_use.html
But you can also create your own easings or use this easings in your own project. They are block-based and you can easily replace them, or create new ones:
typedef CGFloat (^easeBlock)(CGFloat time);
You can use the following optional parameters in the params-dictionary:
[tween start]
when you want to start your tweentypedef void (^tweenBlock)();
typedef void (^updateTweenBlock)(CGFloat progress, CGFloat value);
typedef void (^tweenBlock)();
[GSTween tweenWithTarget:self time:3.0f ease:[Bounce easeOut] params:@{ @"frame": @"{{0,0},{320,568}}", kGSTweenDelay: @2.0f, kGSTweenYoYo: @YES }];
[GSTween tweenWithTarget:self time:3.0f ease:[Bounce easeOut] params:@{ @"frame": @"{{0,0},{320,568}}", kGSTweenDelay: @2.0f, kGSTweenOnUpdate: ^(CGFloat progress, CGFloat value) {
NSLog(@"Current progress: %f", progress);
} }];
You can start, stop, pause or resume a tween
This Library is licensed under the MIT License. Please refer to the LICENSE.txt
for more information.