您的位置:首页 > 其它

商品加入购物车的动画

2016-01-18 09:19 459 查看
额,做一个类似饿了吗加入购物车的动画
先说一下思路,再上代码吧

1.这里主要的难题就是坐标的计算,因为一个是tableView.supperView的坐标(购物车图标),还有一个就是cell中的起始图标,

思路:我的思路就是在

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

此方法中向cell传入购物车的view,这样就能在cell中计算坐标了,具体的计算

- (void)starAnimation {
    //获取cell的tableview
    UITableView *tableView = (UITableView *)self.superview.superview;
    CGRect addFrame = self.addImage.frame;
    CGPoint layerPoint = CGPointMake(self.frame.origin.x+addFrame.origin.x, self.frame.origin.y-tableView.contentOffset.y+addFrame.origin.y+20);
    //获取需要创建的layer的frame
    CGRect layerFrame = CGRectMake(layerPoint.x, layerPoint.y, addFrame.size.width, addFrame.size.height);
    LIUCircleLayer *layer = [LIUCircleLayer layoutWithFrame:layerFrame];
    [self.willGoView.superview.layer insertSublayer:layer above:tableView.layer];
   
    //创建一个队列结构来存储创建的layer,以便结束之后移除
    [self.queue addValue:layer];
    
    [layer addAnimation:[self getAnimationWithStartPoint:CGPointMake(CGRectGetMidX(layerFrame), CGRectGetMidY(layer.frame))] forKey:nil];
}


//我觉得这个就是本次中的难点了

好了 具体完整的代码见github
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: