IOS-当触摸UITextField外部时关闭键盘我想知道当用户触摸到UITextField.
3 回答
喵喔喔
TA贡献1735条经验 获得超5个赞
UITapGestureRecogniser
UITextField
视图DidLoad
UITapGestureRecognizer *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()}
繁星点点滴滴
TA贡献1803条经验 获得超3个赞
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];}
- 3 回答
- 0 关注
- 434 浏览
添加回答
举报
0/150
提交
取消