IOS中对于一些控件的抖动效果
这两天在网上看到一个帖子讨论关于有些app 输入账密时候 错误的话会有抖动效果出现,然后自己琢磨了下如何实现,下面上代码!!!
首先 写一个UIView的分类
#import <UIKit/UIKit.h>
typedef NS_ENUM(NSInteger, QHLDirection) {
QHLDirectionHorizontal,
QHLDirectionVertical
};
@interface UIView (QHLShakes)
- (void)shakeWithShakeDirection:(QHLDirection)shakeDirection;
- (void)shakeWithTimes:(NSInteger)times shakeDirection:(QHLDirection)shakeDirection;
- (void)shakeWithTimes:(NSInteger)times speed:(CGFloat)speed shakeDirection:(QHLDirection)shakeDirection;
- (void)shakeWithTimes:(NSInteger)times speed:(CGFloat)speed range:(CGFloat)range shakeDirection:(QHLDirection)shakeDirection;
@end
#import "UIView+QHLShakes.h"
@implementation UIView (QHLShakes)
- (void)shakeWithShakeDirection:(QHLDirection)shakeDirection {
[self shakeWithTimes: speed:0.05 range: shakeDirection:shakeDirection];
}
- (void)shakeWithTimes:(NSInteger)times shakeDirection:(QHLDirection)shakeDirection {
[self shakeWithTimes:times speed:0.05 range: shakeDirection:shakeDirection];
}
- (void)shakeWithTimes:(NSInteger)times speed:(CGFloat)speed shakeDirection:(QHLDirection)shakeDirection {
[self shakeWithTimes:times speed:speed range: shakeDirection:shakeDirection];
}
- (void)shakeWithTimes:(NSInteger)times speed:(CGFloat)speed range:(CGFloat)range shakeDirection:(QHLDirection)shakeDirection {
[self viewShakesWithTiems:times speed:speed range:range shakeDirection:shakeDirection currentTimes: direction:];
}
/**
* @param times 震动的次数
* @param speed 震动的速度
* @param range 震动的幅度
* @param shakeDirection 哪个方向上的震动
* @param currentTimes 当前的震动次数
* @param direction 向哪边震动
*/
- (void)viewShakesWithTiems:(NSInteger)times speed:(CGFloat)speed range:(CGFloat)range shakeDirection:(QHLDirection)shakeDirection currentTimes:(NSInteger)currentTimes direction:(int)direction{
[UIView animateWithDuration:speed animations:^{
self.transform = (shakeDirection == QHLDirectionHorizontal)? CGAffineTransformMakeTranslation(range * direction, ):CGAffineTransformMakeTranslation(, range * direction);
} completion:^(BOOL finished) {
if (currentTimes >= times) {
[UIView animateWithDuration:speed animations:^{
self.transform = CGAffineTransformIdentity;
}];
return;
}
#pragma mark - 循环到times == currentTimes时候 会跳出该方法
[self viewShakesWithTiems:times -
speed:speed
range:range
shakeDirection:shakeDirection
currentTimes:currentTimes +
direction:direction * -];
}];
}
@en
然后在ViewController.m中 先导入头文件 #import "UIView+QHLShakes.h"
#import "ViewController.h"
#import "UIView+QHLShakes.h" #define QHLFont [UIFont boldSystemFontOfSize:17]
#define QHLColor [UIColor purpleColor]
#define QHLCGColor [QHLColor CGColor] @interface ViewController ()
@property (nonatomic, strong) UITextField *show;
@property (nonatomic, strong) UISegmentedControl *directBtn;
@end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
[self setUpShowTextField];
[self setUpBtn];
} #pragma mark - show
- (void)setUpShowTextField {
UITextField *show = [[UITextField alloc] init];
show.frame = CGRectMake(, , , );
show.textAlignment = NSTextAlignmentCenter;
show.text = @"你是猪吗?";
show.textColor = QHLColor;
show.layer.cornerRadius = ;
show.layer.masksToBounds = YES;
show.layer.borderWidth = 2.0;
show.layer.borderColor = QHLCGColor;
self.show = show;
[self.view addSubview:show];
}
#pragma mark - btn
- (void)setUpBtn {
UIButton *btn = [[UIButton alloc] init];
btn.layer.borderColor = QHLCGColor;
btn.frame = CGRectMake(, , , );
btn.layer.borderWidth = 2.0;
btn.layer.cornerRadius = ;
btn.layer.masksToBounds = YES;
[btn setTitle:@"点我呀" forState:UIControlStateNormal];
[btn setTitle:@"猪是你" forState:UIControlStateHighlighted];
[btn setTitleColor:QHLColor forState:UIControlStateNormal];
[self.view addSubview:btn]; [btn addTarget:self action:@selector(btnDidClick) forControlEvents:UIControlEventTouchUpInside];
}
#pragma mark - btn 点击事件
- (void)btnDidClick {
[self.show shakeWithTimes: speed:0.05 range: shakeDirection:(self.directBtn.selectedSegmentIndex == )?QHLDirectionHorizontal:QHLDirectionVertical];
}
@end
在 - (void)viewDidLoad {} 中添加一个textField和button,然后设置相关的属性,并给button添加点击事件
当点击事件触发的时候,textField抖动!!!!
自己试了textField 和button的抖动效果 别的没试~~~
如果哪里有些错的地方 求大神指点!!!
IOS中对于一些控件的抖动效果的更多相关文章
- Unity3d IOS中的IGUI控件
Unity3d IOS中的IGUI控件 @灰太龙 群63438968 我讲一下IOS中用的UI,我们采用IGUI,需要使用IGUI的高版本,在Unity3d 4.2中也可以使用的! 之前IGUI有个 ...
- IOS中调整UI控件位置和尺寸
1.frame(修改位置和尺寸):以父控件左上角为坐标原点,在其父控件中的位置和尺寸. //frame属性中的坐标点不能直接修改 CGRect tempFrame = self.v.frame; // ...
- ios 中的UI控件学习总结(1)
UIKit框架提供了非常多功能强大又易用的UI控件 下面列举一些在开发中可能用得上的UI控件 UIButton 按钮 UILabel 文本标签 UITextField 文本输入框 UIImageVie ...
- 【转】IOS中各种常用控件的默认高度,很全
1.状态栏 状态栏一般高度为20像素,在打手机或者显示消息时会放大到40像素高,注意,两倍高度的状态栏在好像只能在纵向的模式下使用.如下图 用户可以隐藏状态栏,也可以将状态栏设置为灰色,黑色或者半 ...
- ios中VRGCalendarView日历控件
http://pan.baidu.com/share/link?shareid=4166002480&uk=923776187 官网 https://github.com/TjeerdVuri ...
- 【Animation】 使用handler和Runnable实现某一个控件的抖动效果
布局: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tool ...
- ios开发中关闭textview控件的虚拟键盘
在ios开发中,textfield控件在点击的时候出现虚拟键盘,关掉虚拟键盘可以通过虚拟键盘中的done button和点击view中的任意地方来关闭虚拟键盘. 1.第一种方法是textfield控件 ...
- Xamarin iOS教程之页面控件
Xamarin iOS教程之页面控件 Xamarin iOS 页面控件 在iPhone手机的主界面中,经常会看到一排小白点,那就是页面控件,如图2.44所示.它是由小白点和滚动视图组成,可以用来控制翻 ...
- 在DevExpress程序中使用TeeList控件以及节点查询的处理
在很多情况下,我们需要通过树列表进行数据的展示,如一些有层次关系的数据,通过有层级的展示,能够使用户更加直观查看和管理相关的数据.在一般Winform开发的情况下,可以使用微软的TreeView控件, ...
随机推荐
- traditional:true
- 你好,C++(20).4.2.2 表达并列条件选择的switch语句:如果……如果……如果……
4.2.2 表达并列条件选择的switch语句:如果……如果……如果…… 在现实世界中,还有这样一类特殊的条件选择: 如果明天是晴天,我就穿T恤: 如果明天是阴天,我就穿衬衣: 如果明天是雨天,我就 ...
- ON UPDATE CURRENT_TIMESTAMP
CREATE TABLE time1 ( id SMALLINT, time1 TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TI ...
- 阿里大鱼simplexmlelement object 取值PHP
SimpleXMLElement Object( [code] => 15 [msg] => Remote service error [sub_code] => ...
- JavaScript加密解密压缩工具
<script> a=62; function encode() { var code = document.getElementById('code').value; code = co ...
- PYTHON简介及安装
Python简介 Python是一种广泛使用的高层次,通用,解释,动态编程语言.它的设计理念强调代码的可读性,它的语法允许程序员表达更少的代码的概念比将在可能语言如C ++或Java.该语言提供旨在使 ...
- C语言初学 比较三个数中最大值的问题
#include<stdio.h> #include<math.h> main() { int x,y,n,m ,z; scanf("%d%d%d",&am ...
- jquery幻灯片--渐变
网站上为了设计,需要一些幻灯片效果,现在网站有很多插件可以使用. 想要成为以为牛逼的程序员,绝对不允许只会用别人的插件而已,不然你只能是“代码”的搬运工,而不敢做出自己的创新. 首先使用jquery做 ...
- android 数据存储的几种方式
总体的来讲,数据存储方式有三种:一个是文件,一个是数据库,另一个则是网络.其中文件和数据库可能用的稍多一些,文件用起来较为方便,程序可以自己定义格式:数据库用起稍烦锁一些,但它有它的优点,比如在海量数 ...
- documentElement vs body区别
documentElement.scrollTop------>0因为,他包含head, body body.scrollTop------------------>才是正确的 scrol ...