0

我试图让数字键盘在 IOS 中消失。我已经添加了下面的代码来完成这个,它只是一种工作。我必须选择文本或双击才能让键盘消失。完成此操作后,我单击返回文本框,然后它就可以正常工作了。

- (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];
}
4

1 回答 1

1

将此添加到您的 viewDidLoad

UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self.nameTextField action:@selector(resignFirstResponder)];
gestureRecognizer.cancelsTouchesInView = NO;
[self.view addGestureRecognizer:gestureRecognizer];
于 2012-07-07T19:14:10.763 回答