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

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

    

}

原文地址:https://www.cnblogs.com/Lovexiaohuzi/p/7273585.html