123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- //
- // LZLiveAnimation.m
- // TIANYAN
- //
- // Created by CY on 2021/6/3.
- // Copyright © 2021 leo. All rights reserved.
- //
- #import "LZLiveAnimation.h"
- #define ANGLE_TO_RADIAN(angle) ((angle)/180.0* M_PI)
- @implementation LZLiveAnimation
- + (void)showAnimationWithPoint:(CGPoint)point baseView:(UIView *)baseView{
- UIImage *image = [UIImage imageNamed:@"vqu_images_L_live_touch_animation"];
-
- CGRect rect = CGRectMake(point.x - image.size.width / 2.0f, point.y - image.size.height / 2.0f, image.size.width, image.size.height);
- UIImageView *imgV = [[UIImageView alloc] initWithFrame:rect];
- imgV.image = [UIImage imageNamed:@"vqu_images_L_live_touch_animation"];
- [baseView addSubview:imgV];
-
- NSString *scaleKey = @"transform.scale";
- CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:scaleKey];
- NSInteger scale = (arc4random() % 10) + 10;
- animation.values = @[@(2.0), @(0.6), @(2.0),@(0.6),@(scale * 0.1)];
-
- NSString *rotationKey = @"transform.rotation";
- CAKeyframeAnimation*anim = [CAKeyframeAnimation animationWithKeyPath:rotationKey];
- NSInteger rotation = arc4random() % 30;
- anim.values = @[@(ANGLE_TO_RADIAN(-15)),@(ANGLE_TO_RADIAN(15)),@(ANGLE_TO_RADIAN(-15)),@(ANGLE_TO_RADIAN(15)),@(ANGLE_TO_RADIAN(rotation))];
- CAAnimationGroup *group = [CAAnimationGroup animation];
- group.animations = @[animation,anim];
- group.duration = 0.35f;
- group.removedOnCompletion = NO;
- group.fillMode = kCAFillModeForwards;
- [imgV.layer addAnimation:group forKey:nil];
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.35f * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
- [UIView animateWithDuration:0.25f animations:^{
- imgV.alpha = 0.0f;
- CGRect rect = imgV.frame;
- rect.origin.x -= 10.0f;
- rect.origin.y -= 45.0f;
- imgV.frame = rect;
- } completion:^(BOOL finished) {
- [imgV removeFromSuperview];
- }];
- });
- }
- @end
|