CALayer+SGAnimation.m 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. //
  2. // CALayer+SGAnimation.m
  3. // SGAnimationExample
  4. //
  5. // Created by apple on 2017/6/13.
  6. // Copyright © 2017年 Sorgle. All rights reserved.
  7. //
  8. // - - - - - - - - - - - - - - 交流QQ:1357127436 - - - - - - - - - - - - - - - //
  9. //
  10. // - - 如在使用中, 遇到什么问题或者有更好建议者, 请于 kingsic@126.com 邮箱联系 - - - - //
  11. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  12. // - - GitHub下载地址 https://github.com/kingsic/SGAnimation.git - — - - - - - //
  13. //
  14. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
  15. #import "CALayer+SGAnimation.h"
  16. @implementation CALayer (SGAnimation)
  17. /// 视图动画 (transform)
  18. - (void)SG_animationWithDuration:(CGFloat)duration values:(NSArray *)values {
  19. CAKeyframeAnimation *KFAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
  20. KFAnimation.duration = duration;
  21. KFAnimation.removedOnCompletion = NO;
  22. KFAnimation.fillMode = kCAFillModeForwards;
  23. NSMutableArray *valueArr = [NSMutableArray array];
  24. CGFloat beginValue = [values[0] floatValue];
  25. CGFloat betweenValue = [values[1] floatValue];
  26. CGFloat endValue = [values[2] floatValue];
  27. [valueArr addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(beginValue, beginValue, beginValue)]];
  28. [valueArr addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(betweenValue, betweenValue, betweenValue)]];
  29. [valueArr addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(endValue, endValue, endValue)]];
  30. KFAnimation.values = valueArr;
  31. KFAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
  32. [self addAnimation:KFAnimation forKey:nil];
  33. }
  34. @end