zoukankan      html  css  js  c++  java
  • iOS--实现UIView的抖动效果-类似Mac上密码输入错误效果

    觉得是很不错的一个效果,转来收藏。

    // 直接传值调用下面的方法就OK,需要的拿走吧

    #pragma mark 抖动动画

    - (void)shakeAnimationForView:(UIView *) view

    {
        
        // 获取到当前的View
        
        CALayer *viewLayer = view.layer;
        
        // 获取当前View的位置
        
        CGPoint position = viewLayer.position;
        
        // 移动的两个终点位置
        
        CGPoint x = CGPointMake(position.x + 10, position.y);
        
        CGPoint y = CGPointMake(position.x - 10, position.y);
        
        // 设置动画
        
        CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
        
        // 设置运动形式
        
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
        
        // 设置开始位置
        
        [animation setFromValue:[NSValue valueWithCGPoint:x]];
        
        // 设置结束位置
        
        [animation setToValue:[NSValue valueWithCGPoint:y]];
        
        // 设置自动反转
        
        [animation setAutoreverses:YES];
        
        // 设置时间
        
        [animation setDuration:.06];
        
        // 设置次数
        
        [animation setRepeatCount:3];
        
        // 添加上动画
        
        [viewLayer addAnimation:animation forKey:nil];
        

  • 相关阅读:
    音频波谱通用类|超酷的说
    跟随鼠标的星星实例
    AS3放大镜工具类
    caurina缓动类
    AS3中 is,as,typeof的区别
    Loader ,URLLoader ,URLStream的区别
    (转)AS3正则:元子符,元序列,标志,数量表达符
    动态绘制扇形实例
    AS3.0绘图API
    as3效率优化
  • 原文地址:https://www.cnblogs.com/ChrisYu/p/4878199.html
Copyright © 2011-2022 走看看