商品加入购物车抛物线下坠的动画最近项目中做了一个加入购物车的动画


代码很简单,只有一个方法 

#pragma mark - 购物车动画效果

/**
 加购物车动画
 @param tableView <#tableView description#>
 @param indexPath <#indexPath description#>
 @param picImageView <#picImageView description#>
 */
- (void)startAnimationand:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath picImageView:(UIImageView *)picImageView {
    CGRect rect = [tableView rectForRowAtIndexPath:indexPath];
    //获取当前cell 相对于self.view 当前的坐标
    rect.origin.x = rect.origin.x + 162*SCALAE;
    rect.origin.y = rect.origin.y - [tableView contentOffset].y + 64 + 80*SCALAE;
    CGRect imageViewRect = picImageView.frame;
    imageViewRect.origin.x = rect.origin.x+imageViewRect.origin.x;
    imageViewRect.origin.y = rect.origin.y+imageViewRect.origin.y;
    
    CGPoint finishRect = CGPointMake(KSCREEN_WIDTH-49, KSCREEN_HEIGHT-49);
    
    [[PurchaseCarAnimationHelper shareHelper] startAnimationandView:picImageView andRect:imageViewRect andFinishRect:finishRect andFinishBlock:^(BOOL finisn) {
        [PurchaseCarAnimationHelper shakeAnimation:self.shopCartButton];
    }];
}

tableView就是你自己定义的tablevIew,indexPath为索引,picImageView即为动画的图片!

我是在点击加购物车的代理中,调用这个方法

   [weakSelf startAnimationand:weakSelf.tableView indexPath:indexPath picImageView:cell.itemPicImageView];

要注意的是商品加入购物车抛物线下坠的动画

最后封装好的 PurchaseCarAnimationHelper   

网盘链接: https://pan.baidu.com/s/1i4TURWD

密码: n7q6  (注:封装好的Helper里面 SCALAE 为比例,会报错,你可以自己改)

相关文章: