zoukankan      html  css  js  c++  java
  • 核心动画

    一、瑕疵抖动效果

    这种抖动的幅度很大。

        CAKeyframeAnimation *anim = [CAKeyframeAnimation animation];
        
        anim.keyPath = @"transform.rotation";
        
        // 1. 抖動幅度
        anim.values = @[@(angle2Radion(-5)),@(angle2Radion(5))];
        
        // 2. 一直抖動
        anim.repeatCount = MAXFLOAT;
        
        [_imageV.layer addAnimation:anim forKey:nil];

    二、 正常抖动

    只需要 把下方这句代码 改一下就OK

        // 把这句代码改成 
        anim.values = @[@(angle2Radion(-5)),@(angle2Radion(5))];
    
        // 改成这句代码
        anim.values = @[@(angle2Radion(-5)),@(angle2Radion(5)),@(angle2Radion(-5))];

    三、把抖动效果的原点由图片的中心点改成 左上角

     _imageV.layer.anchorPoint = CGPointZero;

    四、摆动

    - (void)viewDidLoad {
        [super viewDidLoad];
        
        _imageV.layer.anchorPoint = CGPointZero;
    }
    // 抖动效果
    - (void)DouDongXiaoGuo
    {
        CAKeyframeAnimation *anim = [CAKeyframeAnimation animation];
        
        anim.keyPath = @"transform.rotation";
        
        // 1. 抖動幅度还可以使用path
        anim.path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 5, 5)].CGPath;
        
        anim.duration = 1;
        // 2. 一直抖動
        anim.repeatCount = MAXFLOAT;
        
        [_imageV.layer addAnimation:anim forKey:nil];
    }

    五、position 的画圆

       CAKeyframeAnimation *anim = [CAKeyframeAnimation animation];
        
        anim.keyPath = @"position";
        
        // 1. 抖動幅度还可以使用path
        anim.path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(50, 50, 100, 100)].CGPath;
        
        anim.duration = 1;
        // 2. 一直抖動
        anim.repeatCount = MAXFLOAT;
        
        [_imageV.layer addAnimation:anim forKey:nil];

    六、跟随用户所画的线条移动位置

    1. 在SB中拖动一个UIView .

    2. class : WYGrayBgView 类.

    3. 在ViewController中不写任何代码。

    @interface WYGrayBgView ()
    @property (nonatomic,strong) UIBezierPath   *path;
    @end
    
    @implementation WYGrayBgView
    - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
    {
        UITouch *touch = [touches anyObject];
        
        // 获取手指的触摸点
        CGPoint curP = [touch locationInView:self];
        
        // 创建路径
        UIBezierPath *path = [UIBezierPath bezierPath];
        _path = path;
        
        //设置起点
        [path moveToPoint:curP];
    }
    
    - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
    {
        UITouch *touch = [touches anyObject];
        
        //获取手指的触摸点
        CGPoint curP = [touch locationInView:self];
        
        [_path addLineToPoint:curP];
        
        [self setNeedsDisplay];
    }
    
    - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
    {
        //给imageView 添加核心动画
        CAKeyframeAnimation *anim = [CAKeyframeAnimation animation];
        anim.keyPath = @"position";
        
        anim.path = _path.CGPath;
        
        anim.duration = 1;
        
        anim.repeatCount = MAXFLOAT;
        
        [[[self.subviews firstObject] layer] addAnimation:anim forKey:nil];
    }
    
    - (void)drawRect:(CGRect)rect
    {
        [_path stroke];
    }

  • 相关阅读:
    linux安装mongodb数据库./mongod -f mongodb.conf失败或者error
    idea项目提交
    spring5.x日志问题log4j
    IDEA使用apache-tomcat-9.0.16控制台Tomcat日志中文乱码问题
    笔记本网线连服务器内网ip配置
    vue项目启动操作
    win10窗口打开一直处于最小化状态问题
    停止 WinDefend Microsoft Defender Antivirus Service
    关于apt命令和yum命令区别
    20200924-4 代码规范
  • 原文地址:https://www.cnblogs.com/iOS363536404/p/5431017.html
Copyright © 2011-2022 走看看