模仿饿了么、美团添加购物车的动画效果
2016-05-25 00:00
399 查看
摘要: 模仿饿了么、美团添加购物车的动画效果 本赛尔曲线
#pragma mark -加入购物车动画
-(void) JoinCartAnimationWithRect:(CGRect)rect
{
CGFloat _endPoint_x = 35;
CGFloat _endPoint_y = 713 - 35;
CGFloat startX = rect.origin.x;
CGFloat startY = rect.origin.y;
//1.创建佩塞尔曲线:
_path= [UIBezierPath bezierPath];
//设置起点:
[_path moveToPoint:CGPointMake(startX, startY)];
//创建路径:三点曲线
[_path addCurveToPoint:CGPointMake(_endPoint_x, _endPoint_y) controlPoint1:CGPointMake(startX, startY) controlPoint2:CGPointMake(startX - 180, startY - 200)];
//2.创建layer图标:
_dotLayer = [CALayer layer];
_dotLayer.backgroundColor = [UIColor purpleColor].CGColor;
_dotLayer.frame = CGRectMake(0, 0, 20, 20);
_dotLayer.cornerRadius = 5;
_dotLayer.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"01.png"]].CGColor;
[self.view.layer addSublayer:_dotLayer];
//3、组合动画:
[self groupAnimation];
}
#pragma mark - 组合动画
-(void)groupAnimation
{
//1、
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
animation.path = _path.CGPath;
animation.rotationMode = kCAAnimationRotateAuto;
//2、
CABasicAnimation *alphaAnimation = [CABasicAnimation animationWithKeyPath:@"alpha"];
alphaAnimation.duration = 0.5f;
alphaAnimation.fromValue = [NSNumber numberWithFloat:1.0];
alphaAnimation.toValue = [NSNumber numberWithFloat:0.1];
alphaAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
//3、
CAAnimationGroup *groups = [CAAnimationGroup animation];
groups.animations = @[animation,alphaAnimation];
groups.duration = durationTime;
groups.removedOnCompletion = NO;
groups.fillMode = kCAFillModeForwards;
groups.delegate = self;
[groups setValue:@"groupsAnimation" forKey:@"animationName"];
[_dotLayer addAnimation:groups forKey:nil];
[self performSelector:@selector(removeFromLayer:) withObject:_dotLayer afterDelay:durationTime];
}
//执行完后移除:
- (void)removeFromLayer:(CALayer *)layerAnimation{
[layerAnimation removeFromSuperlayer];
}
#pragma mark - CAAnimationDelegate
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
if ([[anim valueForKey:@"animationName"]isEqualToString:@"groupsAnimation"]) {
CABasicAnimation *shakeAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
shakeAnimation.duration = 0.25f;
shakeAnimation.fromValue = [NSNumber numberWithFloat:0.9];
shakeAnimation.toValue = [NSNumber numberWithFloat:1];
shakeAnimation.autoreverses = YES;
// 这里是下方的自定义View上面 放的btn. 自己随便定义一个 0.-
//[_shopCartView.btnBackImg.layer addAnimation:shakeAnimation forKey:nil];
}
}
#pragma mark -加入购物车动画
-(void) JoinCartAnimationWithRect:(CGRect)rect
{
CGFloat _endPoint_x = 35;
CGFloat _endPoint_y = 713 - 35;
CGFloat startX = rect.origin.x;
CGFloat startY = rect.origin.y;
//1.创建佩塞尔曲线:
_path= [UIBezierPath bezierPath];
//设置起点:
[_path moveToPoint:CGPointMake(startX, startY)];
//创建路径:三点曲线
[_path addCurveToPoint:CGPointMake(_endPoint_x, _endPoint_y) controlPoint1:CGPointMake(startX, startY) controlPoint2:CGPointMake(startX - 180, startY - 200)];
//2.创建layer图标:
_dotLayer = [CALayer layer];
_dotLayer.backgroundColor = [UIColor purpleColor].CGColor;
_dotLayer.frame = CGRectMake(0, 0, 20, 20);
_dotLayer.cornerRadius = 5;
_dotLayer.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"01.png"]].CGColor;
[self.view.layer addSublayer:_dotLayer];
//3、组合动画:
[self groupAnimation];
}
#pragma mark - 组合动画
-(void)groupAnimation
{
//1、
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
animation.path = _path.CGPath;
animation.rotationMode = kCAAnimationRotateAuto;
//2、
CABasicAnimation *alphaAnimation = [CABasicAnimation animationWithKeyPath:@"alpha"];
alphaAnimation.duration = 0.5f;
alphaAnimation.fromValue = [NSNumber numberWithFloat:1.0];
alphaAnimation.toValue = [NSNumber numberWithFloat:0.1];
alphaAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
//3、
CAAnimationGroup *groups = [CAAnimationGroup animation];
groups.animations = @[animation,alphaAnimation];
groups.duration = durationTime;
groups.removedOnCompletion = NO;
groups.fillMode = kCAFillModeForwards;
groups.delegate = self;
[groups setValue:@"groupsAnimation" forKey:@"animationName"];
[_dotLayer addAnimation:groups forKey:nil];
[self performSelector:@selector(removeFromLayer:) withObject:_dotLayer afterDelay:durationTime];
}
//执行完后移除:
- (void)removeFromLayer:(CALayer *)layerAnimation{
[layerAnimation removeFromSuperlayer];
}
#pragma mark - CAAnimationDelegate
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
if ([[anim valueForKey:@"animationName"]isEqualToString:@"groupsAnimation"]) {
CABasicAnimation *shakeAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
shakeAnimation.duration = 0.25f;
shakeAnimation.fromValue = [NSNumber numberWithFloat:0.9];
shakeAnimation.toValue = [NSNumber numberWithFloat:1];
shakeAnimation.autoreverses = YES;
// 这里是下方的自定义View上面 放的btn. 自己随便定义一个 0.-
//[_shopCartView.btnBackImg.layer addAnimation:shakeAnimation forKey:nil];
}
}
相关文章推荐
- Apache 和 tomcat 的整合
- hbase regionserver死掉
- SpringMVC入门(个人笔记)
- C++基础知识学习:变量的初始化
- python os模块 常用命令
- 修改 svn 中每次编辑提交的作者 author 名字
- css层叠样式表(2)——层叠样式表的使用
- php生成的csv, 无法完整显示带前导0的数字
- python 源码解析
- 集合(二):List接口。
- Shelve Instance 操作详解 - 每天5分钟玩转 OpenStack(38)
- python玩转大数据-(一)
- log2
- Java 代码块的执行顺序
- CentOS 6.4下安装Oracle 11gR2(x64)
- ORA-28000: the account is locked的解决办法
- oracle默认初始化用户名密码和密码修改
- 忘记oracle的sys用户密码怎么修改
- Linux下建立Oracle服务及其开机自启动
- 企业管理器控制台本地无法访问