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控件, ...
随机推荐
- Centos6.5使用yum安装Mysql5.7
想要玩新的东东就要付出代价,我的时间悄悄的都溜走了,说多了都是泪! 实践才是真理! 系统版本:Linux localhost.localdomain 2.6.32-431.el6.x86_64 #1 ...
- CSS特殊性
样式的优先级取决于特殊性,特殊性为0,0,0,0 Ø每个元素或伪元素选择器贡献特殊性为 0,0,0,1 Ø每个类.伪类或者属性选择器的特殊性为 0,0,1,0 Ø每个ID选择器的特殊性为 0,1,0, ...
- ecmascript 的一些发展新动向
========== ecmascript 的一些发展新动向 (e5a57b27 - initial commit) 更弱.更受限 严格模式禁止 arguments.callee - 可以 " ...
- css应用四
1.Float属性详解 float属性定义元素在哪个方向浮动. Left 左浮动: Right 右浮动: None 默认,不浮动: Inherit 继承父元素float属性. 示例一: <div ...
- CFLAGS/CPPFLAGS/CXXFLAGS in Makefile介绍
先来看一张关于Makefile中的常见预定义变量. CFLAGS 表示用于 C 编译器的选项,CXXFLAGS 表示用于 C++ 编译器的选项.这两个变量实际上涵盖了编译和汇编两个步骤.大多数程序和库 ...
- (转载)Python装饰器学习
转载出处:http://www.cnblogs.com/rhcad/archive/2011/12/21/2295507.html 这是在Python学习小组上介绍的内容,现学现卖.多练习是好的学习方 ...
- [T]各种字符串Hash函数比较
常用的字符串Hash函数还有ELFHash,APHash等等,都是十分简单有效的方法.这些函数使用位运算使得每一个字符都对最后的函数值产生影响.另外还有以MD5和SHA1为代表的杂凑函数,这些函数几乎 ...
- list排序成员函数对string对象与char*对象排序的差别
对list容器中的对象排序,不能使用sort()算法,只能采用其自身的排序函数sort().因为,算法sort()只支持随机存取的容器的排序,如vector等. 对基本数据对象list排序:成员函数s ...
- bzoj1145
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1145 神题...... 定义f(abcd)为高度排名为abcd的个数,例如闪电的个数为f(13 ...
- java开发经验分享(二)
二. 数据库 1. SQL语句中保留字.函数名要大写,表明.字段名全部小写 如:SELECT vc_name,vc_sex,i_age FROM user WHERE i_id = 100 AND i ...