灵感来源于 UIView-EasingFunctions,在实现上有所不同,本插件不使用 AHEasing,而是使用 CAMediaTimingFunction。主要是因为之前提到的仓库不支持 ios8,导致动画出现跳动,并且存在 64 位架构的问题。
请参阅 easings.net 了解所有不同的缓动效果。
只需将 UIView+Easing.h & UIView+Easing.m 文件导入到您的项目目录中,并按以下方式使用
[self.dialogView setEasingFunction:easeOutBack forKeyPath:@"center"];
[UIView animateWithDuration:.6 animations:^{
self.dialogView.center = CGPointMake(CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds));
} completion:^(BOOL finished) {
[self.dialogView removeEasingFunctionForKeyPath:@"center"];
[self.dialogView removeEasingFunctionForKeyPath:@"transform"];
}];
使用您自定义的缓动函数
[self.button setEasingFunction:CreateCAMediaTimingFunction(0.47, 0, 0.745, 0.715) forKeyPath:@"center"];
[UIView animateWithDuration:.6 animations:^{
self.button.center = CGPointMake(160,80);
} completion:^(BOOL finished) {
[self.button removeEasingFunctionForKeyPath:@"center"];
}];
关注 Twitter (@tapthaker)