ios 添加到购物车的动画

    func addProductsAnimation(iamgeView : UIImageView)
    {

        //创建一个一模一样的涂层
        let frame = iamgeView.convertRect(iamgeView.bounds, toView: self.view)
        let transitionLayer = CALayer()
        transitionLayer.frame = frame;
        transitionLayer.contents = iamgeView.layer.contents
        //涂层添加到view中
        self.view.layer.addSublayer(transitionLayer)
        self.animationLayers?.append(transitionLayer)
        //定义起点和终点
        let p1 = transitionLayer.position;
        let p3 = CGPointMake(self.view.width - view.width / 4 - view.width / 8 - 6, self.view.layer.bounds.size.height - 40);
        //添加一条贝赛尔路径
        let positionAnimation = CAKeyframeAnimation(keyPath: "position")
        let path = CGPathCreateMutable();
        CGPathMoveToPoint(path, nil, p1.x, p1.y);
        CGPathAddCurveToPoint(path, nil, p1.x, p1.y - 30, p3.x, p1.y - 30, p3.x, p3.y);
        positionAnimation.path = path;
        //设置透明度
        let opacityAnimation = CABasicAnimation(keyPath: "opacity")
        opacityAnimation.fromValue = 1
        opacityAnimation.toValue = 0.9
        opacityAnimation.fillMode = kCAFillModeForwards
        opacityAnimation.removedOnCompletion = true
        //设置transform
        let transformAnimation = CABasicAnimation(keyPath: "transform")
        transformAnimation.fromValue = NSValue(CATransform3D: CATransform3DIdentity)
        transformAnimation.toValue = NSValue(CATransform3D: CATransform3DScale(CATransform3DIdentity, 0.2, 0.2, 1))
        
        //创建一个动画组
        let groupAnimation = CAAnimationGroup()
        groupAnimation.animations = [positionAnimation, transformAnimation, opacityAnimation];
        groupAnimation.duration = 0.8
        groupAnimation.delegate = self;
        //添加动画组
         transitionLayer.addAnimation(groupAnimation, forKey: "cartParabola")
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值