This is my code below. I can call my numpad but I can't hide it. How to hide it?
- (IBAction)loopBtn:(id)sender {
loopBtn.keyboardType = UIKeyboardTypeNumberPad;
[loopBtn becomeFirstResponder];
[sender resignFirstResponder];
}
UIView
您可以通过使您的 an UIControl
( UIControl
is subclass of UIView
)来隐藏键盘。然后编写一个IBAction
在您触摸它时执行的方法UIControl
(以前UIView
)。打开界面编辑器并选择 main UIView
。然后打开身份检查器并将其类更改为UIControl
from UIView
。现在在您的视图控制器中编写一个 IBAction 方法。
-(IBAction)hideKeyboard:(id)sender
{
[self.view endEditing:YES];
}
现在将您的 UIView 的 TouchUpInside 事件连接到此 IBAction 方法。每当您在文本字段之外触摸时,这将隐藏键盘。