• 添加购物车动画


    #import "Solo_Cart_Methon.h"
    #define Screen_W    [UIScreen mainScreen].bounds.size.width
    #define Screen_H    [UIScreen mainScreen].bounds.size.height
    
    @interface Solo_Cart_Methon()
    {
        CALayer     *_layer;
    }
    @property(nonatomic,strong)CALayer *layer;
    @property(nonatomic,strong)UIBezierPath *path;
    @end
    @implementation Solo_Cart_Methon
    
    +(void)startAnimationWithRect:(CGRect)rect
                        ImageView:(UIImageView *)imageView
                     donghua_view:(UIView*)donghua_view
                       super_view:(UIView*)super_view
                        end_point:(CGPoint)end_point
                         end_view:(UIView*)end_view
    {
        Solo_Cart_Methon *solo_cart_methon  = [Solo_Cart_Methon new];
        solo_cart_methon.donghua_view       = donghua_view;
        solo_cart_methon.super_view         = super_view;
        solo_cart_methon.end_point          = end_point;
        solo_cart_methon.end_view           = end_view;
        
        [solo_cart_methon startAnimationWithRect:rect ImageView:imageView];
    }
    -(void)startAnimationWithRect:(CGRect)rect
                        ImageView:(UIImageView *)imageView
    {
        if (!_layer)
        {
            _layer = [CALayer layer];
            _layer.contents = (id)imageView.layer.contents;
            
            _layer.contentsGravity = kCAGravityResizeAspectFill;
            _layer.bounds = rect;
            [_layer setCornerRadius:CGRectGetHeight([_layer bounds]) / 2];
            _layer.masksToBounds = YES;
            _layer.position = CGPointMake(imageView.center.x, CGRectGetMidY(rect)+64);
            
            
            [self.super_view.layer addSublayer:_layer];
            
            self.path = [UIBezierPath bezierPath];
            [self.path moveToPoint:_layer.position];
            
            //  the track you can custom
            //  point-> point1 ->point2
            [self.path addCurveToPoint:self.end_point
                         controlPoint1:CGPointMake(Screen_W/4,self.end_point.y+50)
                         controlPoint2:CGPointMake(self.end_point.x-50, self.end_point.y-50)];
            
        }
        [self groupAnimation];
    }
    -(void)groupAnimation
    {
        self.donghua_view.userInteractionEnabled = NO;
        CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
        animation.path = _path.CGPath;
        animation.rotationMode = kCAAnimationRotateAuto;
        CABasicAnimation *expandAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
        expandAnimation.duration        = 0.2f;
        expandAnimation.fromValue       = [NSNumber numberWithFloat:1];
        expandAnimation.toValue         = [NSNumber numberWithFloat:0.8f];
        expandAnimation.timingFunction  =[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
        
        
        CABasicAnimation *narrowAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
        narrowAnimation.beginTime   = 0.2f;
        narrowAnimation.duration    = 0.5f;
        narrowAnimation.fromValue   = [NSNumber numberWithFloat:0.8f];
        narrowAnimation.toValue     = [NSNumber numberWithFloat:0.3f];
        narrowAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
        
        CAAnimationGroup *groups = [CAAnimationGroup animation];
        groups.animations = @[animation,expandAnimation,narrowAnimation];
        groups.duration = 0.7;
        groups.removedOnCompletion=NO;
        groups.fillMode=kCAFillModeForwards;
        groups.delegate = self;
        [_layer addAnimation:groups forKey:@"group"];
    }
    -(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
    {
        if (anim == [_layer animationForKey:@"group"])
        {
            self.donghua_view.userInteractionEnabled = YES;
            [_layer removeFromSuperlayer];
            _layer = nil;
            CATransition *animation = [CATransition animation];
            animation.duration = 0.25f;
            CABasicAnimation *shakeAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
            shakeAnimation.duration = 0.25f;
            shakeAnimation.fromValue = [NSNumber numberWithFloat:-5];
            shakeAnimation.toValue = [NSNumber numberWithFloat:5];
            shakeAnimation.autoreverses = YES;
            [self.end_view.layer addAnimation:shakeAnimation forKey:nil];
        }
    }
    
    @end
  • 相关阅读:
    Linux官方源、镜像源汇总
    python3 pip报错 TypeError: 'module' object is not callable
    2019-11-27:kali 2019-4中文乱码解决方法
    2019-11-26:密码学基础知识,csrf防御
    2019-11-25:信息收集,笔记
    2019-11-24:postgresql数据库安装,最后报错failed to load SQLModule 问题的解决方案
    2019-11-22:xss绕过笔记
    2019-11-20:xss学习笔记
    2019-11-19:无返回的盲型xxe,使用带外读取数据
    2019-11-19:xxe漏洞利用,笔记
  • 原文地址:https://www.cnblogs.com/lidongq/p/5540830.html
Copyright © 2020-2023  润新知