zoukankan      html  css  js  c++  java
  • 类似直播点赞动画(出现一颗心缓缓升起然后消失)

    - (void)addPraiseAnimation {

        

        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(kUIScreenWidth-45, kUIScreenHeight/1.7-55-64, 25, 25)];

        imageView.alpha = 0;

        imageView.backgroundColor = [UIColor clearColor];

        imageView.clipsToBounds = YES;

        //  用0.2秒的时间将imageView的透明度变成1.0,同时将其放大1.3倍,再缩放至1.1倍,这里参数根据需求设置

        [UIView animateWithDuration:0.2 animations:^{

            imageView.alpha = 1.0;

            imageView.frame = CGRectMake(kUIScreenWidth-45, kUIScreenHeight/1.7-55-64, 25, 25);

            CGAffineTransform transFrom = CGAffineTransformMakeScale(1.3, 1.3);

            imageView.transform = CGAffineTransformScale(transFrom, 1, 1);

        }];

        //  imageView放到view上

        [_imageView addSubview:imageView];

        //  动画结束点的X值

        CGFloat finishX = kUIScreenWidth-45;

        //  动画结束点的Y值

        CGFloat finishY = kUIScreenHeight/1.7-120-64;

        //  imageView在运动过程中的缩放比例

        CGFloat scale = round(random() % 2) + 0.7;

        // 生成一个作为速度参数的随机数

        CGFloat speed = 1 / round(random() % 900) + 0.6;

        //  动画执行时间

        NSTimeInterval duration = 4 * speed;

        

        //  开始动画

        [UIView beginAnimations:nil context:nil];

        //  设置动画时间

        [UIView setAnimationDuration:duration];

        //  图片名字

        imageView.image = [UIImage imageNamed:@"icon_wxzx_love"];

        //  设置imageView的结束frame

        imageView.frame = CGRectMake( finishX, finishY, 25 * scale, 25 * scale);

        //  设置渐渐消失的效果,这里的时间最好和动画时间一致

        [UIView animateWithDuration:duration animations:^{

            imageView.alpha = 0;

        }];

        //  设置动画代理

        [UIView setAnimationDelegate:self];

        [UIView commitAnimations];

        

    }

  • 相关阅读:
    ingress高可用--使用DaemonSet方式部署ingress-nginx
    flask-Migrate模块
    flask 框架 前端和后端请求超时问题
    linux crontab执行python脚本问题
    python 装饰器
    Python 中实现装饰器时使用 @functools.wraps 的理由
    jquery ui dialog 中使用select2 导致select2的input失去焦点的解决方法
    Django之ModelForm组件
    Django之Model操作
    Java环境变量,真的还有必要配吗?
  • 原文地址:https://www.cnblogs.com/Lovexiaohuzi/p/7273585.html
Copyright © 2011-2022 走看看