ios 购物车商品下落动画

属性: 


@property (nonatomic, strong) NSMutableArray *animationLayers;

@property (nonatomic, assign) BOOL isNeedNotification;

@property (nonatomic, assign) BOOL isAnimating;

方法: 

- (void)addProductsAnimation:(UIImageView *)imageView dropToPoint:(CGPoint)dropToPoint isNeedNotification:(BOOL)isNeedNotification {

    

    

    

    //若正在做动画,就结束,防止连续点击

    if (self.isAnimating) {

        // return;

    }

    

    self.isAnimating = YES;

    

    self.isNeedNotification = isNeedNotification;

    if (self.animationLayers == nil) {

        self.animationLayers = [[NSMutableArray alloc] init];

    }

    

    CGRect frame = [imageView convertRect:imageView.bounds toView:APPDELEGATE.window];

    CALayer *transitionLayer = [[CALayer alloc] init];

    transitionLayer.frame = frame;

    transitionLayer.contents = imageView.layer.contents;

    [APPDELEGATE.window.layer addSublayer:transitionLayer];

    [self.animationLayers addObject:transitionLayer];

    

    CGPoint point1 = transitionLayer.position;

    

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

    CGMutablePathRef path = CGPathCreateMutable();

    CGPathMoveToPoint(path, nil, point1.x, point1.y);

    CGPathAddCurveToPoint(path, nil, point1.x, point1.y - 30, dropToPoint.x, point1.y - 30, dropToPoint.x, dropToPoint.y);

    positionAnimation.path = path;

    

    CABasicAnimation *opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];

    opacityAnimation.fromValue = @1;

    opacityAnimation.toValue = @0.9;

    

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

    transformAnimation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];

    transformAnimation.toValue = [NSValue valueWithCATransform3D:CATransform3DScale(CATransform3DIdentity, 0.2, 0.2, 1)];

    

    CAAnimationGroup *groupAnimation = [CAAnimationGroup animation];

    groupAnimation.animations = @[positionAnimation, transformAnimation, opacityAnimation];

    groupAnimation.duration = 0.5;

    groupAnimation.delegate = self;

    groupAnimation.fillMode = kCAFillModeForwards;

    groupAnimation.removedOnCompletion = YES;

    

    [transitionLayer addAnimation:groupAnimation forKey:@"cartParabola"];

    

}


- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {

    

    self.isAnimating = NO;

    

    if (self.animationLayers.count > 0) {

        CALayer *layer = self.animationLayers[0];

        layer.hidden = YES;

        [layer removeFromSuperlayer];

        [self.animationLayers removeObjectAtIndex:0];

        [APPDELEGATE.window.layer removeAnimationForKey:@"cartParabola"];

        if (self.isNeedNotification) {

            [[NSNotificationCenter defaultCenter] postNotificationName:@"shopCarAnimationEnd" object:nil];

        }

//        if (_addShopCarFinished) {

//            self.addShopCarFinished();

//        }

    }

}


调用:

   [self addProductsAnimation:self.goodImage dropToPoint:CGPointMake(Width * 0.625, Height - 50) isNeedNotification:YES];



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值