LZLiveAnimation.m 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //
  2. // LZLiveAnimation.m
  3. // TIANYAN
  4. //
  5. // Created by CY on 2021/6/3.
  6. // Copyright © 2021 leo. All rights reserved.
  7. //
  8. #import "LZLiveAnimation.h"
  9. #define ANGLE_TO_RADIAN(angle) ((angle)/180.0* M_PI)
  10. @implementation LZLiveAnimation
  11. + (void)showAnimationWithPoint:(CGPoint)point baseView:(UIView *)baseView{
  12. UIImage *image = [UIImage imageNamed:@"vqu_images_L_live_touch_animation"];
  13. CGRect rect = CGRectMake(point.x - image.size.width / 2.0f, point.y - image.size.height / 2.0f, image.size.width, image.size.height);
  14. UIImageView *imgV = [[UIImageView alloc] initWithFrame:rect];
  15. imgV.image = [UIImage imageNamed:@"vqu_images_L_live_touch_animation"];
  16. [baseView addSubview:imgV];
  17. NSString *scaleKey = @"transform.scale";
  18. CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:scaleKey];
  19. NSInteger scale = (arc4random() % 10) + 10;
  20. animation.values = @[@(2.0), @(0.6), @(2.0),@(0.6),@(scale * 0.1)];
  21. NSString *rotationKey = @"transform.rotation";
  22. CAKeyframeAnimation*anim = [CAKeyframeAnimation animationWithKeyPath:rotationKey];
  23. NSInteger rotation = arc4random() % 30;
  24. anim.values = @[@(ANGLE_TO_RADIAN(-15)),@(ANGLE_TO_RADIAN(15)),@(ANGLE_TO_RADIAN(-15)),@(ANGLE_TO_RADIAN(15)),@(ANGLE_TO_RADIAN(rotation))];
  25. CAAnimationGroup *group = [CAAnimationGroup animation];
  26. group.animations = @[animation,anim];
  27. group.duration = 0.35f;
  28. group.removedOnCompletion = NO;
  29. group.fillMode = kCAFillModeForwards;
  30. [imgV.layer addAnimation:group forKey:nil];
  31. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.35f * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  32. [UIView animateWithDuration:0.25f animations:^{
  33. imgV.alpha = 0.0f;
  34. CGRect rect = imgV.frame;
  35. rect.origin.x -= 10.0f;
  36. rect.origin.y -= 45.0f;
  37. imgV.frame = rect;
  38. } completion:^(BOOL finished) {
  39. [imgV removeFromSuperview];
  40. }];
  41. });
  42. }
  43. @end