博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS--输入密码错误的时候,抖动
阅读量:4708 次
发布时间:2019-06-10

本文共 1773 字,大约阅读时间需要 5 分钟。

直接上代码:

////  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
*)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

 

转载于:https://www.cnblogs.com/LzwBlog/p/5744382.html

你可能感兴趣的文章
做衡八的日子(转自VFleaking)
查看>>
day7.条件和循环
查看>>
(转)log4j(二)——如何控制日志信息的输出?
查看>>
JavaScript简介
查看>>
php.ini中safe_mode开启对PHP系统函数的影响
查看>>
gdb
查看>>
字符串与整数、浮点数、无符号整数之间的转换常用函数
查看>>
ubuntu清理旧内核
查看>>
有关UIImageView+AFNetworking 下载图片的线程问题
查看>>
Node之安装篇
查看>>
Android的Animation之LayoutAnimation使用方法
查看>>
二分图最大匹配算法-Hopcroft-Karp模板
查看>>
发布和订阅的删除
查看>>
如何使用qtp12 utf进行功能测试
查看>>
使用LinQ进行增删改查
查看>>
索引作用 和缺点
查看>>
eclipse 背景颜色
查看>>
Tomcat连接池配置-DBCP
查看>>
aliyun阿里云Maven仓库地址和其他地址
查看>>
Mercedes-Benz won’t start| Step by Step Troubleshooting Guide
查看>>