• 核心动画


    一、瑕疵抖动效果

    这种抖动的幅度很大。

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

  • 相关阅读:
    启动mysql时显示:/tmp/mysql.sock 不存在的解决方法
    python在使用MySQLdb模块时报Can't extract file(s) to egg cacheThe following error occurred while trying to extract file(s) to the Python eggcache的错误。
    文档发布测试
    我的日常
    CSS-基础优化策略
    Git-基本操作
    Git-配置SSH公钥
    Git-免密提交
    Wx-mpvue开发小程序
    Vue-移动端开发全家桶
  • 原文地址:https://www.cnblogs.com/iOS363536404/p/5431017.html
Copyright © 2020-2023  润新知