IOS-当触摸UITextField外部时关闭键盘我想知道当用户触摸到UITextField.
3 回答
jeck猫
TA贡献1909条经验 获得超7个赞
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贡献1875条经验 获得超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 关注
- 359 浏览
添加回答
举报
0/150
提交
取消