CAAnimation+VLCWiggle.m 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*****************************************************************************
  2. * VLC for iOS
  3. *****************************************************************************
  4. * Copyright (c) 2015 VideoLAN. All rights reserved.
  5. * $Id$
  6. *
  7. * Authors: Tobias Conradi <videolan # tobias-conradi.de>
  8. *
  9. * Refer to the COPYING file of the official project for license.
  10. *****************************************************************************/
  11. #import "CAAnimation+VLCWiggle.h"
  12. @implementation CAAnimation (VLCWiggle)
  13. + (instancetype)vlc_wiggleAnimationwithSoftMode:(BOOL)softmode
  14. {
  15. CAKeyframeAnimation *position = [CAKeyframeAnimation animation];
  16. position.keyPath = @"position";
  17. position.values = @[
  18. [NSValue valueWithCGPoint:CGPointZero],
  19. [NSValue valueWithCGPoint:CGPointMake(-1, 0)],
  20. [NSValue valueWithCGPoint:CGPointMake(1, 0)],
  21. [NSValue valueWithCGPoint:CGPointMake(-1, 1)],
  22. [NSValue valueWithCGPoint:CGPointMake(1, -1)],
  23. [NSValue valueWithCGPoint:CGPointZero]
  24. ];
  25. position.timingFunctions = @[
  26. [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
  27. [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]
  28. ];
  29. position.additive = YES;
  30. CAKeyframeAnimation *rotation = [CAKeyframeAnimation animation];
  31. rotation.keyPath = @"transform.rotation";
  32. if (softmode) {
  33. rotation.values = @[
  34. @0,
  35. @0.005,
  36. @0,
  37. [NSNumber numberWithFloat:-0.004]
  38. ];
  39. } else {
  40. rotation.values = @[
  41. @0,
  42. @0.03,
  43. @0,
  44. [NSNumber numberWithFloat:-0.02]
  45. ];
  46. }
  47. rotation.timingFunctions = @[
  48. [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
  49. [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]
  50. ];
  51. CAAnimationGroup *group = [[CAAnimationGroup alloc] init];
  52. group.animations = @[position, rotation];
  53. group.duration = 0.4;
  54. group.repeatCount = HUGE_VALF;
  55. return group;
  56. }
  57. @end