ios - 单击完成按钮后 UITexfled 保持焦点

标签 ios objective-c uitextfield

我是 xCode 和 Objective C 的新手。我正在开发一个简单的计算器应用程序,只是为了学习... 我已尽我所能,通过谷歌搜索并搜索来寻找答案,但仍卡在一些事情上......

我有一个文本字段,当有人单击 UIPickerView 时,它会获取一个值。这工作正常,但是当我使用下面的代码单击“完成”按钮时,它会保持焦点。 我已经尝试过 EndFirstRepsonder 和 EndEditing,但都没有删除闪烁的光标...

顺便说一句,动画仅在显示时有效,并且无法隐藏...

//Show Picker Wheel
- (IBAction)showPickerWheel:(id)sender 
 {

  //This line hides the default keyboard
  [sender resignFirstResponder];

  [UIView beginAnimations:nil context:nil];
  [UIView setAnimationDuration:0.6];
  CGAffineTransform transfrom = CGAffineTransformMakeTranslation(0, 20);
  _pickerViewContainer.transform = transfrom;
  _pickerViewContainer.alpha = 1;
  [UIView commitAnimations];

 }


//Hide Picker Wheel
- (IBAction)hidePickerWheel:(id)sender 
 {

  [UIView beginAnimations:nil context:nil];
  [UIView setAnimationDuration:0.6];
  CGAffineTransform transfrom = CGAffineTransformMakeTranslation(0, 20);
  _pickerViewContainer.transform = transfrom;
  _pickerViewContainer.alpha = 0;
  [UIView commitAnimations];

 }

最佳答案

您需要像这样在 didEndEditing 委托(delegate)方法中 resignFirstResponder:

(BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

关于ios - 单击完成按钮后 UITexfled 保持焦点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20842391/

相关文章:

ios - @""的替代品?

iphone - 如何更改 UINavigationBar 中的编辑/完成按钮标题

php - 尝试移植 C++ 代码以将文件上传到服务器到 Objective-C,但它不起作用

ios - 如果 UITextField 为空,则不会出现 UIAlert

ios - 在哪里最好使用 Watch Connectivity 调用 updateApplicationContext?

ios - 向选定的表格单元格添加复选标记还会检查另一个表格单元格

android - microsoft band 如何从自定义磁贴读取心率或某些传感器数据并与移动应用程序通信?

objective-c - iPad应用程序中包含的runtime.h无法编译

ios - 在 UITableView 重新加载时以编程方式打开/关闭 UITextField 的 inputView

ios - 如何使用 UINavigationBar 中的 UITextView 导航到下一个 UIViewController