猿问
回到首页
个人中心
反馈问题
注册登录
下载APP
首页
课程
实战
体系课
手记
专栏
慕课教程
IOS-当触摸UITextField外部时关闭键盘
IOS-当触摸UITextField外部时关闭键盘
我想知道当用户触摸到
UITextField
.
慕田峪7331174
浏览 360
回答 3
3回答
jeck猫
您需要添加一个UITapGestureRecogniser并将其分配到视图中,然后在UITextField上面是选择器。守则:视图DidLoadUITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)];[self.view addGestureRecognizer:tap];解雇键盘:-(void)dismissKeyboard { [aTextField resignFirstResponder];}(在哪里aTextField是负责键盘的文本字段)SWIFT 3版本看起来是这样的let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.dismissKeyboard (_:)))self.view.addGestureRecognizer(tapGesture)解雇键盘func dismissKeyboard (_ sender: UITapGestureRecognizer) { aTextField.resignFirstResponder()}
0
0
0
翻过高山走不出你
我想出了几个答案。使用在viewDidLoad:UIGestureRecognizer *tapper;- (void)viewDidLoad{ [super viewDidLoad]; tapper = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)]; tapper.cancelsTouchesInView = NO; [self.view addGestureRecognizer:tapper];}删除当前正在编辑的内容:- (void)handleSingleTap:(UITapGestureRecognizer *) sender{ [self.view endEditing:YES];}
0
0
0
打开App,查看更多内容
随时随地看视频
慕课网APP
相关分类
iOS
继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续