• 类似直播点赞动画(出现一颗心缓缓升起然后消失)


    - (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];

        

    }

  • 相关阅读:
    Java 进制转换
    k-近邻算法实例
    Java JTS & 空间数据模型
    Java中 &&与&,||与|的区别
    http https 区别
    四种DCOM错误的区别,0x80080005 0x800706be 0x80010105 0x
    OPC测试常用的OPCClient和OPCServer软件推荐
    关于TFS2010 远程无法创建团队项目的若干问题总结
    我对NHibernate的感受(4):令人欣喜的Interceptor机制
    我对NHibernate的感受(3):有些尴尬的集合支持
  • 原文地址:https://www.cnblogs.com/Lovexiaohuzi/p/7273585.html
Copyright © 2020-2023  润新知