简体   繁体   English

使用文本字段时,即时通讯试图使键盘在IOS中消失

[英]When using a text field, im trying to get the keyboard to go away in IOS

I am trying to make the number pad disappear in IOS. 我试图使数字键盘在IOS中消失。 I have added the code below to accomplish this and it only kind of works. 我添加了以下代码来完成此操作,这只是一种工作。 I have to select text or double press to get the keyboard to go away. 我必须选择文本或连按两次才能使键盘消失。 Once I have done this, and I click back into the text box, then it works like it should. 一旦完成此操作,然后单击返回文本框,则它将按应有的方式工作。

- (IBAction)didBeginEditingPointsText:(id)sender
{
    self.tap = [[UITapGestureRecognizer alloc] initWithTarget:self

                                                       action:@selector(dismissKeyboard)];
    [self.view addGestureRecognizer:self.tap];
}

-(void)dismissKeyboard
{
    [self.pointsText resignFirstResponder];
    [self.view removeGestureRecognizer:self.tap];
}

Add this to your viewDidLoad 将此添加到您的viewDidLoad

UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self.nameTextField action:@selector(resignFirstResponder)];
gestureRecognizer.cancelsTouchesInView = NO;
[self.view addGestureRecognizer:gestureRecognizer];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM