TFAnimator(时间函数动画器)是一个库,允许您使用任何时间函数来动画化应用程序的任何UI组件。
使用弹性动画移动视图
CGFloat xS = self.xSource;
CGFloat yS = self.ySource;
CGFloat wS = self.wSource;
CGFloat hS = self.hSource;
CGFloat xDelta = self.xFinal - self.xSource;
CGFloat yDelta = self.yFinal - self.ySource;
CGFloat wDelta = self.wFinal - self.wSource;
CGFloat hDelta = self.hFinal - self.hSource
[TFAnimator animateWithTimingFunction:PRTweenTimingFunctionElasticOut
duration:05.f
animation:^(CGFloat normalizedValue) {
CGFloat x = xS + xDelta*normalizedValue;
CGFloat y = yS + yDelta*normalizedValue;
CGFloat w = wS + wDelta*normalizedValue;
CGFloat h = hS + hDelta*normalizedValue;
view.frame = CGRectMake(x, y, w, h);
}
completion:nil];
在动画中更改颜色
CGFloat r = self.redSource;
CGFloat g = self.greenSource;
CGFloat b = self.blueSource;
CGFloat rDelta = (self.redFinal - self.redSource)/255.f;
CGFloat gDelta = (self.greenFinal - self.greenSource)/255.f;
CGFloat bDelta = (self.blueFinal - self.blueSource)/255.f;
[TFAnimator animateWithTimingFunction:PRTweenTimingFunctionLinear
duration:1.f
animation:^(CGFloat normalizedValue) {
CGFloat newR = fmin(fmax(r+rDelta*normalizedValue, 0), 1);
CGFloat newG = fmin(fmax(g+gDelta*normalizedValue, 0), 1);
CGFloat newB = fmin(fmax(b+bDelta*normalizedValue, 0), 1);
view.backgroundColor = [UIColor colorWithRed:newR green:newG blue:newB alpha:1.0f];
}
completion:nil];
在动画中更改标签文本
double start = 0;
double final = 100000000;
[TFAnimator animateWithTimingFunction:PRTweenTimingFunctionExpoOut
duration:.3f
animation:^(CGFloat normalizedValue) {
double newValue = final*normalizedValue;
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
label.text = [NSString stringWithFormat:@"%.2f", newValue];
}
completion:^{}];
更多示例请参阅示例文件夹。
TFAnimator之所以能够实现这样的动画,得益于PRTween时间函数。PRTween不仅包含时间函数,它还是一个允许您进行动画的库。请参阅:https://github.com/domhofmann/PRTween/
BSD