CAAnimation+VLCWiggle.m 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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_wiggleAnimation
  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. rotation.values = @[
  33. @0,
  34. @0.03,
  35. @0,
  36. [NSNumber numberWithFloat:-0.02]
  37. ];
  38. rotation.timingFunctions = @[
  39. [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
  40. [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]
  41. ];
  42. CAAnimationGroup *group = [[CAAnimationGroup alloc] init];
  43. group.animations = @[position, rotation];
  44. group.duration = 0.4;
  45. group.repeatCount = HUGE_VALF;
  46. return group;
  47. }
  48. @end