关于京东购物车动画

来源:互联网 发布:淘宝介入后怎么撤销 编辑:程序博客网 时间:2024/05/01 18:43

-(void)clickShoppingCar

{

    self.bottomView.countLabel.hidden = NO;

    shoppingConunt +=1;

    self.bottomView.countLabel.text = [NSStringstringWithFormat:@"%ld",(long)shoppingConunt];

    

    //添加一个用于动画的imageview

    UIImageView * image = [[UIImageViewalloc] initWithImage:[UIImageimageNamed:@"iconfont-ttpodicon-2"]];

    image.frame =CGRectMake(Screen_weight-120,CGRectGetMinX(self.bottomView.frame),20, 20);

    [self.viewaddSubview:image];

    //绘制贝塞尔曲线

    UIBezierPath *path=[UIBezierPathbezierPath];

    path.lineWidth =5.0;

    path.lineCapStyle =kCGLineCapRound//线条拐角

    path.lineJoinStyle =kCGLineCapRound//终点处理

    [path moveToPoint:CGPointMake(Screen_weight-30,Screen_height-35)];

    [path addQuadCurveToPoint:CGPointMake(Screen_weight-150,Screen_height-35)controlPoint:CGPointMake(Screen_weight-60,Screen_height-200)];

    

    [pathstroke];


    //创建关键帧

    CAKeyframeAnimation *moveAnimation=[CAKeyframeAnimationanimationWithKeyPath:@"position"];

    //设置属性

    moveAnimation.path=path.CGPath;

    //    moveAnimation.duration=2.0;

    //    //添加动画到layer

    //    [self.imageView.layer addAnimation:moveAnimation forKey:nil];

    

    

    //缩放动画

    CABasicAnimation *scaleAnimation=[CABasicAnimationanimationWithKeyPath:@"transform"];

    //初始状态为变形前的常量的那个状态  由于formValue属性需要id类型,所以将常量封装成对象类型

    scaleAnimation.fromValue=[NSValuevalueWithCATransform3D:CATransform3DIdentity] ;

    scaleAnimation.toValue=[NSValuevalueWithCATransform3D:CATransform3DMakeScale(0.5,0.5, 1)];

    //scaleAnimation.duration=2.0;

    //    [self.imageView.layer addAnimation:scaleAnimation forKey:nil];

    

    

    //透明度动画

    CABasicAnimation *alphaAnimation=[CABasicAnimationanimationWithKeyPath:@"opacity"];

    alphaAnimation.fromValue=@1.0;

    alphaAnimation.toValue=@0.0;

    //    alphaAnimation.duration=2.0;

    //    [self.imageView.layer addAnimation:alphaAnimation forKey:nil];

    //可以创建动画组来管理所有动画,统一设置动画时长及统一添加到某个视图的layer

    CAAnimationGroup *group=[CAAnimationGroupanimation];

    group.animations=@[moveAnimation,scaleAnimation];//三种动画都可以自己加

    group.duration=1.0;

    [image.layeraddAnimation:group forKey:nil];

    

}


1 0
原创粉丝点击