UIView之endEditing方法
来源:互联网 发布:淘宝95小嫩模全集 编辑:程序博客网 时间:2024/06/05 20:57
面介绍下endEditing:方法,该方法为UIView中的一个方法,定义为
1
- (BOOL)endEditing:(BOOL)force
官网文档释义:
Causes the view (or one of its embedded text fields) to resign the first responder status.
This method looks at the current view and its subview hierarchy for the text field that is currently the first responder. If it finds one, it asks that text field to resign as first responder. If the force parameter is set to YES, the text field is never even asked; it is forced to resign.
大意为:
注销当前view(或它下属嵌入的text fields)的first responder 状态。
该方法会在当前view以及其subview层次结构中需找当前处于first responder状态的text field。如果找到的话会注销其first responder状态,如果指定force参数为YES,则不再询问text field,而直接强制注销其first responder状态。
好了,有了这个快捷方法,在FormViewController中,则不需要在实现UITextFieldDelegate,来对处于编辑状态的textField进行跟踪,也不必担心将来会添加N个UITextView,只要是在FormViewController下,我们
只要调用
?
1
[self.view endEditing:YES];
键盘立马关闭!
这段代码加在 控制器里面,可以监听所有的textField和textView ,方便之处就在于不用谢代理方法去取消第一响应,当控件多的时候会显得比较麻烦
- (void)setKeyBoardAutoHidden{
NSNotificationCenter *notificationCenter = [NSNotificationCenterdefaultCenter];
//SingleTap Gesture
UITapGestureRecognizer *singleTapGesture = [[UITapGestureRecognizeralloc] initWithTarget:selfaction:@selector(backgroundTapDismissKeyboard:)];
NSOperationQueue *mainQueue = [NSOperationQueuemainQueue];
//UIKeyboardWillShowNotification
[notificationCenter addObserverForName:UIKeyboardWillShowNotificationobject:nilqueue:mainQueue usingBlock:^(NSNotification *note) {
[self.viewaddGestureRecognizer:singleTapGesture];
}];
//UIKeyboardWillHideNotification
[notificationCenter addObserverForName:UIKeyboardWillHideNotificationobject:nilqueue:mainQueue usingBlock:^(NSNotification *note) {
[self.viewremoveGestureRecognizer:singleTapGesture];
}];
}
- (void) backgroundTapDismissKeyboard:(UIGestureRecognizer *) gestureRecognizer{
//将self.view里所有的subview的first responder都resign掉
[self.viewendEditing:YES];
}
- UIView之endEditing方法
- UIView之endEditing方法
- UIView之endEditing方法
- UIView - endEditing
- endEditing
- iOS之UIView常用方法总结
- UIView常用方法之setNeedsDisplay和setNeedsLayout
- UIView常用方法之setNeedsDisplay和setNeedsLayout
- UIView剖析之Draw、Size、Layout方法
- uiview方法
- 根视图之UIView的一些基本方法
- IPhone 之 UIView的一些基本方法理解
- UIView常用的一些方法小记之setNeedsDisplay和setNeedsLayout
- IOS UIView 之实例方法篇 Instance Methods
- UIView常用的一些方法小记之setNeedsDisplay和setNeedsLayout
- UI 常用方法总结之--- UIWindow UIView (不断更新中)
- UIView常用的一些方法之setNeedsDisplay和setNeedsLayout
- 根视图之UIView的一些基本方法
- 更改版本号 真机不能运行
- Bayesian Net Example
- Html5基于SVG的扁平风格圆形进度条javascript插件教程
- java.sql.SQLException: Io exception: Connection reset
- VSFTPD全攻略(/etc/vsftpd/vsftpd.conf文件详解)
- UIView之endEditing方法
- 《失控》:最干货编录与总结
- Android NDK开发之 arm_neon.h文件ABI说明
- Excel导入数据自己定义的
- response压缩响应
- (Linux)TCP连接过程状态详解
- Android Http编程之HttpClient
- yuicompressor 与 maven结合,打包,压缩js,css
- 其无前例的springmvc+mybatis后台漂亮框架源代码