CAAnimation+CoinAnimation.m 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // CAAnimation+CoinAnimation.m
  3. // BuguLive
  4. //
  5. // Created by yy on 17/1/6.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "CAAnimation+CoinAnimation.h"
  9. @implementation CAAnimation (CoinAnimation)
  10. + (CAKeyframeAnimation *)jitterAnimation
  11. {
  12. //缩小
  13. CAKeyframeAnimation* jitterAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
  14. jitterAnimation.duration = 0.5;
  15. NSArray *values = @[
  16. [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.6, 0.6, 1.0)],
  17. [NSValue valueWithCATransform3D:CATransform3DMakeScale(1.2, 1.2, 1.0)],
  18. [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9, 0.9, 1.0)],
  19. [NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]
  20. ];
  21. jitterAnimation.values = values;
  22. jitterAnimation.removedOnCompletion = YES;
  23. return jitterAnimation;
  24. }
  25. + (CABasicAnimation *) AlphaLight:(float)time fromValue:(float)fromValue toValue:(float)toValue
  26. {
  27. CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
  28. animation.fromValue = [NSNumber numberWithFloat:fromValue];
  29. animation.toValue = [NSNumber numberWithFloat:toValue]; //这是透明度。
  30. animation.autoreverses = YES;
  31. animation.duration = time;
  32. animation.repeatCount = MAXFLOAT;
  33. animation.removedOnCompletion = NO;
  34. animation.fillMode = kCAFillModeForwards;
  35. animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
  36. return animation;
  37. }
  38. + (CAAnimationGroup *)coinMoveAntimationWithBegin:(CGPoint)begin WithEnd:(CGPoint)end andMoveTime:(CGFloat)moveTime andNarrowTime:(CGFloat)narrowTime andNarrowFromValue:(CGFloat)narrowFromValue andNarrowToValue:(CGFloat)narrowToValue
  39. {
  40. //移动
  41. CAKeyframeAnimation *moveAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
  42. moveAnimation.values = @[
  43. [NSValue valueWithCGPoint:begin],
  44. [NSValue valueWithCGPoint:end]
  45. ];
  46. moveAnimation.fillMode = kCAFillModeForwards;
  47. moveAnimation.removedOnCompletion = NO;
  48. moveAnimation.duration = moveTime;
  49. //缩小
  50. CABasicAnimation *narrowAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; ;
  51. narrowAnimation.fromValue = [NSNumber numberWithFloat:narrowFromValue]; // 开始时的倍率
  52. narrowAnimation.toValue = [NSNumber numberWithFloat:narrowToValue]; // 结束时的倍率
  53. narrowAnimation.duration = narrowTime;
  54. narrowAnimation.fillMode = kCAFillModeForwards;
  55. narrowAnimation.removedOnCompletion = NO;
  56. narrowAnimation.beginTime = moveTime;
  57. CAAnimationGroup *groupAntimation = [CAAnimationGroup animation];
  58. groupAntimation.animations = @[moveAnimation,narrowAnimation];
  59. groupAntimation.duration = moveTime + narrowTime;
  60. groupAntimation.fillMode = kCAFillModeForwards;
  61. groupAntimation.removedOnCompletion = NO;
  62. [groupAntimation setValue:@"moveGroupAnimation"
  63. forKey:@"moveGroupAnimation"];
  64. return groupAntimation;
  65. }
  66. @end