UITextField点击textField外任意区域键盘回收(一)---- [UIAppllication shareApplication]
2015-11-25 16:36
351 查看
最近做的项目用到好多textField, 涉及到键盘回收,键盘挡住textField 上移textField等,自己水平不够,深感textfield好复杂,想好好整理下自己会得用法,继续学习不会的用法。。
键盘回收有好多中方法:UITextFieldDelegate, 在self.view上添加UIControl, TouchesBegan方法,[UIAppllication shareApplication]方法
其中点击textField外任意区域回收键盘,这三种方法可以实现:self.view上添加UIControl, TouchesBegan方法,[UIAppllication shareApplication]
方法1 [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
1、第一步
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.automaticallyAdjustsScrollViewInsets = NO;
//创建self.view上的各种控件。。。。
//创建完所有控件后,在此添加手势 保证加在self.view的最外层
//设置点击任何其他位置 键盘回收
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapBG:)];
[self.view addGestureRecognizer:tapGesture];
}
2、第二步 手势action 调用UIApplication sharedApplication
- (void)tapBG:(UITapGestureRecognizer *)gesture {
[[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
}
即可实现点击textField外任意区域回收键盘。。。
键盘回收有好多中方法:UITextFieldDelegate, 在self.view上添加UIControl, TouchesBegan方法,[UIAppllication shareApplication]方法
其中点击textField外任意区域回收键盘,这三种方法可以实现:self.view上添加UIControl, TouchesBegan方法,[UIAppllication shareApplication]
方法1 [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
1、第一步
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.automaticallyAdjustsScrollViewInsets = NO;
//创建self.view上的各种控件。。。。
//创建完所有控件后,在此添加手势 保证加在self.view的最外层
//设置点击任何其他位置 键盘回收
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapBG:)];
[self.view addGestureRecognizer:tapGesture];
}
2、第二步 手势action 调用UIApplication sharedApplication
- (void)tapBG:(UITapGestureRecognizer *)gesture {
[[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
}
即可实现点击textField外任意区域回收键盘。。。
相关文章推荐
- iOS开发多线程-GCD的常见用法
- Android动画之属性动画(二)
- android编译分析之9—dumpvar.mk
- C# 微信扫码支付 回调页面
- setVisibility()设置过度动画
- Android超简易侧滑菜单的实现
- android动画总结
- iOS开发-object-c之 @[], @{}
- Objective-C中的@dynamic
- iOS使用GData对webService进行解析xml
- 完美主义:实现iOS输入框自动移动
- IOS 图片压缩
- 提示框第三方库之MBProgressHUD iOS toast效果 动态提示框效果
- 微信扫码支付模式二支付状态Ajax轮询实例
- 微信中得到的GPS经纬度放在百度,腾迅地图中不准的原因及处理
- Cocos2dx3.6屏幕适配
- iOS中旋转加载动画的实现
- 做android爽到爆的东西,一般人我不告诉他
- Android学习——Animation动画效果
- Android View的second layout pass