Ios 我能';不要隐藏键盘
帮帮我! 在将一个文本字段更改为另一个文本字段时,我无法隐藏键盘 我点击“用户”文本字段弹出选择器,点击“密码”文本字段,弹出键盘,但如果再次点击“用户”则不会隐藏键盘Ios 我能';不要隐藏键盘,ios,swift,keyboard,Ios,Swift,Keyboard,帮帮我! 在将一个文本字段更改为另一个文本字段时,我无法隐藏键盘 我点击“用户”文本字段弹出选择器,点击“密码”文本字段,弹出键盘,但如果再次点击“用户”则不会隐藏键盘 override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { userNameTextField.resignFirstResponder() userPasswordTextField.r
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
userNameTextField.resignFirstResponder()
userPasswordTextField.resignFirstResponder()
}
func textFieldDidBeginEditing(textField: UITextField) {
if textField == userNameTextField {
pickerUser.hidden = false
print("userNameTextField")
} else {
pickerUser.hidden = true
print("@userPasswordTextField")
}
}
@IBAction func userNameTextFieldStartEdit(sender: AnyObject) {
userNameTextField.resignFirstResponder()
userPasswordTextField.resignFirstResponder()
pickerUser.hidden = false
}
func textFieldShouldReturn(textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
覆盖函数触摸开始(触摸:设置,withEvent事件:UIEvent?){
userNameTextField.resignFirstResponder()
userPasswordTextField.resignFirstResponder()
}
func textField didbeginediting(textField:UITextField){
如果textField==用户名textField{
pickerUser.hidden=false
打印(“用户名文本字段”)
}否则{
pickerUser.hidden=true
打印(“@userPasswordTextField”)
}
}
@iAction func userNameTextFieldStartEdit(发件人:AnyObject){
userNameTextField.resignFirstResponder()
userPasswordTextField.resignFirstResponder()
pickerUser.hidden=false
}
func textField应返回(textField:UITextField)->Bool{
textField.resignFirstResponder()辞职
返回真值
}
tyr下面只有一行附加模块:
func textFieldDidBeginEditing(textField: UITextField) {
if textField == userNameTextField {
textField.resignFirstResponder() // this line add
pickerUser.hidden = false
print("userNameTextField")
} else {
pickerUser.hidden = true
print("@userPasswordTextField")
}
}
tyr以下仅一行附加模块:
func textFieldDidBeginEditing(textField: UITextField) {
if textField == userNameTextField {
textField.resignFirstResponder() // this line add
pickerUser.hidden = false
print("userNameTextField")
} else {
pickerUser.hidden = true
print("@userPasswordTextField")
}
}
我认为应该调用该函数来隐藏键盘:
func textFieldShouldReturn(textField: UITextField) -> Bool
{
textField.resignFirstResponder()
return true
}
而不是您的pickerUser.hidden=true
而且:
class ViewController: UIViewController, UITextFieldDelegate {
(你有那个吗?我想你应该调用这个函数来隐藏你的键盘:
func textFieldShouldReturn(textField: UITextField) -> Bool
{
textField.resignFirstResponder()
return true
}
而不是您的pickerUser.hidden=true
而且:
class ViewController: UIViewController, UITextFieldDelegate {
(你有那个吗?使用这个代码
func textFieldDidBeginEditing(textField: UITextField) {
if textField == userNameTextField {
pickerUser.hidden = false
print("userNameTextField")
self.view.endEditing(true)
} else {
pickerUser.hidden = true
print("@userPasswordTextField")
}
}
func textFieldShouldBeginEditing(textField: UITextField) -> Bool {
if(textField == userNameTextField) {
self.view.endEditing(true)
return true
}
return true
}
它对我有用,希望它对我有帮助
func textFieldDidBeginEditing(textField: UITextField) {
if textField == userNameTextField {
pickerUser.hidden = false
print("userNameTextField")
self.view.endEditing(true)
} else {
pickerUser.hidden = true
print("@userPasswordTextField")
}
}
func textFieldShouldBeginEditing(textField: UITextField) -> Bool {
if(textField == userNameTextField) {
self.view.endEditing(true)
return true
}
return true
}
这对我很有用,希望对我有帮助这是预期的行为-当你点击文本字段时,它会成为第一响应者并显示键盘。尝试将点击手势识别器添加到视图本身(您的白色背景),然后使用
视图从那里取消键盘。endEditing(true)
检查我的答案其工作精细这是预期的行为-当您点击文本字段时,它将成为第一响应者并显示键盘。尝试将点击手势识别器添加到视图本身(您的白色背景),然后使用view.endEditing(true)
检查我的答案是否正确是否有UITextFieldDelegate?是否有UITextFieldDelegate?添加断点并检查此方法调用。此方法不会调用您已设置的textfield委托。请添加断点并检查此方法调用。此方法不会调用您已设置textfield委托。谢谢!它的作品,但第一次点击用户文本字段隐藏键盘,第二次点击用户文本字段弹出选择器问题:这是正常的,只有第二次点击弹出一个键盘?这个代码对我来说工作正常,然后我点击第二次它的正常显示选择器不显示键盘谢谢!这是可行的,但是第一次点击用户文本字段隐藏键盘,第二次点击用户文本字段弹出选择器问题:只有第二次点击弹出键盘是正常的吗?这段代码对我来说工作正常,然后我第二次点击它的正常显示选择器不显示键盘