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];
    }

  • 相关阅读:
    开启休眠命令(用户找不到休眠复选框)
    小Q书桌(兼容win10)
    截图,仅截取活动窗口快捷键:Alt + Print Screen SysRq
    Windows10安装Dig命令工具
    拷贝文件保留原创建日期
    重装系统后,QQ(TIM)迁移聊天记录到指定位置
    完全拷贝命令
    Windows10/7 视频、图片、文档、音乐、收藏夹 等文件夹没有原始图标及中文名的解决方案
    js 判断日期大小、是否在时间范围内等处理
    Sql语句 表中相同的记录(某个字段)只显示一条,按照时间排序显示最大或最小
  • 原文地址:https://www.cnblogs.com/iOS363536404/p/5431017.html
Copyright © 2011-2022 走看看