OliveappButtonAnimationLayer.m 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // OliveappButtonAnimationLayer.m
  3. // AppSampleYitu
  4. //
  5. // Created by kychen on 17/1/16.
  6. // Copyright © 2017年 Oliveapp. All rights reserved.
  7. //
  8. #import "OliveappButtonAnimationLayer.h"
  9. @implementation OliveappButtonAnimationLayer
  10. - (instancetype)initWithFrame:(CGRect)frame {
  11. if (self = [super init]) {
  12. self.bounds = frame;
  13. self.cornerRadius = frame.size.width / 2;
  14. self.backgroundColor = [UIColor clearColor].CGColor;
  15. self.borderWidth = frame.size.width / 2.2;
  16. CGColorRef yellowTransport = CGColorCreateCopyWithAlpha([UIColor yellowColor].CGColor, 0.0f);
  17. self.borderColor = yellowTransport;
  18. CGColorRelease(yellowTransport);
  19. [self setZPosition:100.0f];
  20. }
  21. return self;
  22. }
  23. - (void)animationAt:(CGPoint)position
  24. withTransformArray:(NSArray *)array
  25. withParentLayer:(CALayer *)buttonLayer{
  26. [CATransaction begin];
  27. [CATransaction setDisableActions:YES];
  28. self.position = position;
  29. [CATransaction commit];
  30. [CATransaction begin];
  31. [CATransaction setAnimationDuration:0.1f];
  32. self.borderColor = [UIColor yellowColor].CGColor;
  33. [CATransaction commit];
  34. //
  35. CABasicAnimation * animation = [CABasicAnimation animation];
  36. animation.fromValue = @(self.borderWidth);
  37. animation.keyPath = @"borderWidth";
  38. animation.toValue = @(0.0f);
  39. animation.duration = 0.2f;
  40. self.borderWidth = 0.0f;
  41. __weak typeof(self) weakSelf = self;
  42. animation.delegate = weakSelf;
  43. [self addAnimation:animation forKey:nil];
  44. //
  45. if (buttonLayer != nil) {
  46. CAKeyframeAnimation * animation = [CAKeyframeAnimation animation];
  47. animation.beginTime = CACurrentMediaTime() + 0.2f;
  48. animation.keyPath = @"contents";
  49. animation.duration = 0.2f;
  50. animation.values = array;
  51. [buttonLayer addAnimation:animation forKey:nil];
  52. }
  53. }
  54. - (void)animationDidStop:(CABasicAnimation *)anim
  55. finished:(BOOL)flag {
  56. [CATransaction setDisableActions:YES];
  57. self.borderWidth = self.bounds.size.width / 2.2;
  58. CGColorRef yellowTransport = CGColorCreateCopyWithAlpha([UIColor yellowColor].CGColor, 0.0f);
  59. self.borderColor = yellowTransport;
  60. CGColorRelease(yellowTransport);
  61. }
  62. @end