Guest User

Untitled

a guest
Apr 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. CABasicAnimation* rotationXAnimation;
  2. rotationXAnimation = [CABasicAnimation animationWithKeyPath:@"position.y"];
  3. rotationXAnimation.fromValue = [NSNumber numberWithFloat: ((UIControl *) sender).center.y-1.0 ];
  4. rotationXAnimation.toValue = [NSNumber numberWithFloat: ((UIControl *) sender).center.y+1.0 ];
  5. rotationXAnimation.duration = 0.2;
  6. rotationXAnimation.cumulative = NO;
  7. rotationXAnimation.repeatCount = 10.0;
  8. rotationXAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
  9.  
  10. [((UIControl *) sender).layer addAnimation:rotationXAnimation forKey:@"upDownAnimation"];
  11.  
  12. CABasicAnimation* rotationAnimation;
  13. rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
  14. rotationAnimation.fromValue = [NSNumber numberWithFloat: -M_PI * 0.02 ];
  15. rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 0.02 ];
  16. rotationAnimation.duration = 0.2;
  17. rotationAnimation.cumulative = NO;
  18. rotationAnimation.repeatCount = 10.0;
  19. rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
  20.  
  21. [((UIControl *) sender).layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
  22.  
  23. CABasicAnimation* scaleAnimation;
  24. scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
  25. scaleAnimation.fromValue = [NSNumber numberWithFloat: 0.95 ];
  26. scaleAnimation.toValue = [NSNumber numberWithFloat: +1.05 ];
  27. scaleAnimation.duration = 0.1;
  28. scaleAnimation.cumulative = NO;
  29. scaleAnimation.repeatCount = 10.0;
  30. scaleAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
  31.  
  32. [((UIControl *) sender).layer addAnimation:scaleAnimation forKey:@"scaleAnimation"];
  33.  
  34. - (void)earthquake:(UIView*)itemView
  35. {
  36. CGFloat t = 2.0;
  37. CGAffineTransform leftQuake = CGAffineTransformTranslate(CGAffineTransformIdentity, t, -t);
  38. CGAffineTransform rightQuake = CGAffineTransformTranslate(CGAffineTransformIdentity, -t, t);
  39.  
  40. itemView.transform = leftQuake; // starting point
  41.  
  42. [UIView beginAnimations:@"earthquake" context:itemView];
  43. [UIView setAnimationRepeatAutoreverses:YES]; // important
  44. [UIView setAnimationRepeatCount:4];
  45. [UIView setAnimationDuration:0.07];
  46. [UIView setAnimationDelegate:self];
  47. [UIView setAnimationDidStopSelector:@selector(earthquakeEnded:finished:context:)];
  48.  
  49. itemView.transform = rightQuake; // end here & auto-reverse
  50.  
  51. [UIView commitAnimations];
  52. }
  53.  
  54. - (void)earthquakeEnded:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
  55. {
  56. if ([finished boolValue])
  57. {
  58. UIView* item = (UIView *)context;
  59. item.transform = CGAffineTransformIdentity;
  60. }
  61. }
Add Comment
Please, Sign In to add comment