OliveappMouthLayer.m 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //
  2. // OliveappMouthLayer.m
  3. // AppSampleYitu
  4. //
  5. // Created by Xiaoyang Lin on 17/2/8.
  6. // Copyright © 2017年 Oliveapp. All rights reserved.
  7. //
  8. #import "OliveappMouthLayer.h"
  9. @implementation OliveappMouthLayer
  10. - (void)animationFadeIn: (CGFloat) scale
  11. withDuration: (CGFloat) duration
  12. withDelay: (CGFloat) delay {
  13. [CATransaction begin];
  14. [CATransaction setDisableActions:YES];
  15. self.opacity = 0;
  16. [CATransaction commit];
  17. CABasicAnimation * animation1 = [CABasicAnimation animation];
  18. animation1.keyPath = @"opacity";
  19. animation1.fromValue = [NSNumber numberWithFloat:0.f];
  20. animation1.toValue = [NSNumber numberWithFloat:1.f];
  21. animation1.duration = duration;
  22. CABasicAnimation * animation2 = [CABasicAnimation animation];
  23. animation2.keyPath = @"transform";
  24. animation2.fromValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(scale, scale, 1)];
  25. animation2.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(1, 1, 1)];
  26. animation2.duration = duration;
  27. [self addAnimation:animation1 forKey:nil];
  28. [self addAnimation:animation2 forKey:nil];
  29. }
  30. - (void)animationFadeOut: (CGFloat) scale
  31. withDuration: (CGFloat) duration
  32. withDelay: (CGFloat) delay {
  33. [CATransaction begin];
  34. [CATransaction setDisableActions:YES];
  35. self.opacity = 0;
  36. [CATransaction commit];
  37. CABasicAnimation * animation1 = [CABasicAnimation animation];
  38. animation1.keyPath = @"opacity";
  39. animation1.fromValue = [NSNumber numberWithFloat:1.f];
  40. animation1.toValue = [NSNumber numberWithFloat:0.f];
  41. animation1.duration = duration;
  42. animation1.beginTime = CACurrentMediaTime() + delay;
  43. CABasicAnimation * animation2 = [CABasicAnimation animation];
  44. animation2.keyPath = @"transform";
  45. animation2.fromValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(1, 1, 1)];
  46. animation2.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(scale, scale, 1)];
  47. animation2.duration = duration;
  48. animation2.beginTime = CACurrentMediaTime() + delay;
  49. [self addAnimation:animation1 forKey:nil];
  50. [self addAnimation:animation2 forKey:nil];
  51. }
  52. @end