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")
}
ios 添加到购物车的动画
最新推荐文章于 2020-08-03 13:36:53 发布