I'm Terrence

TimingFuntion

函数实现 TimingFunctionLinear,EaseIn,EaseOut,EaseInOut

@protocol TimingFuntionImp<NSObject>

-(CGFloat)update:(CGFloat)t;

@end

@interface TimingFuntionLinear : NSObject<TimingFuntionImp>

@end

@interface TimingFuntionEaseIn : NSObject<TimingFuntionImp>

@end

@interface TimingFuntionEaseOut : NSObject<TimingFuntionImp>

@end

@interface TimingFuntionEaseInOut : NSObject<TimingFuntionImp>

@end

@implementation TimingFuntionLinear

-(CGFloat)update:(CGFloat)t
{
    return t;
}

@end

@implementation TimingFuntionEaseIn

-(CGFloat)update:(CGFloat)t
{
    return powf(t, rateConstant);
}

@end

@implementation TimingFuntionEaseOut

-(CGFloat)update:(CGFloat)t{
    return 1.0-powf((1.0-t), rateConstant);
}

@end

@implementation TimingFuntionEaseInOut

-(CGFloat) update: (CGFloat) t
{
    t *= 2;
    if (t < 1)
        return 0.5f * powf (t, rateConstant);
    else
        return 0.5f * (2.0f - powf(2.0 - t, rateConstant));
}

@end

原理挺简单,无非就是用一次函数,幂函数的图像来理解,重拾一下高中数学知识。。