您的位置:首页 > 其它

关于京东购物车动画

2015-10-26 14:55 302 查看
-(void)clickShoppingCar
{

self.bottomView.countLabel.hidden
= NO;

shoppingConunt +=
1;

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

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

UIImageView * image = [[UIImageView
alloc]
initWithImage:[UIImage
imageNamed:@"iconfont-ttpodicon-2"]];
image.frame =
CGRectMake(Screen_weight-120,
CGRectGetMinX(self.bottomView.frame),
20, 20);
[self.view
addSubview:image];

//绘制贝塞尔曲线

UIBezierPath *path=[UIBezierPath
bezierPath];
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)];

[path
stroke];

//创建关键帧

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

//设置属性
moveAnimation.path=path.CGPath;

// moveAnimation.duration=2.0;

// //添加动画到layer中

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

//缩放动画

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

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

scaleAnimation.fromValue=[NSValue
valueWithCATransform3D:CATransform3DIdentity] ;

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

//scaleAnimation.duration=2.0;

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

//透明度动画

CABasicAnimation *alphaAnimation=[CABasicAnimation
animationWithKeyPath:@"opacity"];
alphaAnimation.fromValue=@1.0;
alphaAnimation.toValue=@0.0;

// alphaAnimation.duration=2.0;

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

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

CAAnimationGroup *group=[CAAnimationGroup
animation];
group.animations=@[moveAnimation,scaleAnimation];//三种动画都可以自己加
group.duration=1.0;
[image.layer
addAnimation:group
forKey:nil];

}

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