Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
tutorials:custom_transitions [2011/07/04 08:29] – Added that you should use a category, as that is not obvious at least to me. 62.109.51.31tutorials:custom_transitions [2013/03/05 10:19] (current) – external edit 127.0.0.1
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:
 +
 +<code objc SPTransitions+CustomTransitions.h>
 +#import <Foundation/Foundation.h>
 + 
 +#define SPCT_TRANSITION_EASE_OUT_ELASTIC_SHORT @"easeOutElasticShort"
 + 
 +@interface SPTransitions (CustomTransitions)
 + 
 ++ (float)easeOutElasticShort:(float)ratio;
 + 
 +@end
 +</code>
 +
 +<code objc SPTransitions+CustomTransitions.m>
 +#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
 +</code>
  tutorials/custom_transitions.txt · Last modified: 2013/03/05 10:19 by 127.0.0.1
 
Powered by DokuWiki