# Differences

This shows you the differences between two versions of the page.

 tutorials:custom_transitions [2011/07/01 17:59]daniel created tutorials:custom_transitions [2013/03/05 10:19] (current) 2011/07/04 08:29 Added that you should use a category, as that is not obvious at least to me. 2011/07/01 17:59 daniel created Next revision Previous revision 2011/07/04 08:29 Added that you should use a category, as that is not obvious at least to me. 2011/07/01 17:59 daniel created Line 1: Line 1: + ====== Custom transitions ====== + To add a custom transition, you just have to extend the ''​SPTransitions''​ class using a category, and add your custom transition. The name of the transition method will be the name that you have to use when you create the tween. Here is a sample: + + ​ + #import <​Foundation/​Foundation.h>​ + + #define SPCT_TRANSITION_EASE_OUT_ELASTIC_SHORT @"​easeOutElasticShort"​ + + @interface SPTransitions (CustomTransitions) + + + (float)easeOutElasticShort:​(float)ratio;​ + + @end + ​ + + ​ + #import "​SPTransitions+CustomTransitions.h"​ + + @implementation SPTransitions (CustomTransitions) + + + (float)easeOutElasticShort:​(float)ratio + { + if (ratio == 0.0f || ratio == 1.0f) return ratio; + else + { + float bounce_factor = -5.0f; + float p = 0.6f; + float s = p / 4.0f; + return powf(2.0f, bounce_factor*ratio) * sinf((ratio-s)*TWO_PI/​p) + 1.0f; + } + } + + @end +