• iOS--输入密码错误的时候,抖动


    直接上代码:

    //
    //  ViewController.m
    //  密码错误--抖动动画
    //
    //  Created by 刘志武 on 16/8/6.
    //  Copyright © 2016年 zhiwuLiu. All rights reserved.
    //
    
    #import "ViewController.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(50, 300, 200, 30)];
        label.backgroundColor = [UIColor purpleColor];
        label.tag = 1000;
        [self.view addSubview:label];
        
        
        
    }
    
    -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
        
        UILabel *label = [self.view viewWithTag:1000];
        
        [self shakeAnimationForView:label];
        
        
    }
    
    #pragma mark 抖动动画
    - (void)shakeAnimationForView:(UIView *) view
    {
        // 获取到当前的View
        CALayer *viewLayer = view.layer;
        // 获取当前View的位置
        CGPoint position = viewLayer.position;
        // 移动的两个终点位置
        CGPoint x = CGPointMake(position.x + 5, position.y);
        CGPoint y = CGPointMake(position.x - 5, position.y);
        // 设置动画
        CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
        // 设置运动形式
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
        // 设置开始位置
        [animation setFromValue:[NSValue valueWithCGPoint:x]];
        // 设置结束位置
        [animation setToValue:[NSValue valueWithCGPoint:y]];
        // 设置自动反转
        [animation setAutoreverses:YES];
        // 设置时间
        [animation setDuration:.06];
        // 设置次数
        [animation setRepeatCount:3];
        // 添加上动画
        [viewLayer addAnimation:animation forKey:nil];
        
    }
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    @end
  • 相关阅读:
    【飞谷六期】爬虫项目3
    Design Pattern
    Markdown
    Git
    Storm-源码分析汇总
    Storm-源码分析-acker (backtype.storm.daemon.acker)
    Storm-源码分析-Topology Submit-Executor
    Storm-源码分析-Topology Submit-Executor-mk-threads
    Storm-源码分析- bolt (backtype.storm.task)
    Storm-源码分析- spout (backtype.storm.spout)
  • 原文地址:https://www.cnblogs.com/LzwBlog/p/5744382.html
Copyright © 2020-2023  润新知