Iphone 如何使键盘消失?

Iphone 如何使键盘消失?,iphone,objective-c,cocoa-touch,keyboard,Iphone,Objective C,Cocoa Touch,Keyboard,有没有一种方法可以让键盘在不退出FirstResponder的情况下消失?我有一个UITextField,我希望它能够接受新文本,并且在屏幕上没有键盘的情况下仍然可以看到插入点(闪烁的光标) 当我执行[textField resignFirstResponder]时,我仍然可以通过附加到textField.text来插入文本,但我再也看不到插入点了 有没有一种标准的方法可以让键盘动画化,同时让我的文本字段保持第一反应 谢谢。如果有,则iPhone API中没有记录。而且,你所要求的也没有意义。您

有没有一种方法可以让键盘在不退出FirstResponder的情况下消失?我有一个
UITextField
,我希望它能够接受新文本,并且在屏幕上没有键盘的情况下仍然可以看到插入点(闪烁的光标)

当我执行
[textField resignFirstResponder]
时,我仍然可以通过附加到
textField.text
来插入文本,但我再也看不到插入点了

有没有一种标准的方法可以让键盘动画化,同时让我的文本字段保持第一反应


谢谢。

如果有,则iPhone API中没有记录。而且,你所要求的也没有意义。您希望在UITextField中具有插入点。好的,太好了。但你还想让键盘消失?那么文本字段具有焦点的意义是什么?如何将数据输入文本字段?如果您想拥有一个自定义键盘,只需将其显示在键盘顶部即可。我想不出一个好的理由,为什么你希望光标是可见的,但没有某种数据输入机制。这将打破用户界面惯例,甚至可能导致你的应用被拒绝。

如果有,那么iPhone API中没有记录。而且,你所要求的也没有意义。您希望在UITextField中具有插入点。好的,太好了。但你还想让键盘消失?那么文本字段具有焦点的意义是什么?如何将数据输入文本字段?如果您想拥有一个自定义键盘,只需将其显示在键盘顶部即可。我想不出一个好的理由,为什么你希望光标是可见的,但没有某种数据输入机制。这将打破用户界面惯例,甚至可能导致你的应用被拒绝。

找到了这个问题的答案。不过,这并不是标准的,正如戴夫所说,可能是应用程序审查者的禁忌。使用此页面中的代码作为起点:

我添加了一个动画块。您可以使用标准外观的动画关闭keyboards视图,但无论第一响应者是什么,都将保留该状态。实际上,键盘只是隐藏在屏幕外

- (void)hideKeyboard 
{
  for (UIWindow *keyboardWindow in [[UIApplication sharedApplication] windows]) {

    // Now iterating over each subview of the available windows
    for (UIView *keyboard in [keyboardWindow subviews]) {

      // Check to see if the view we have referenced is UIKeyboard.
      // If so then we found the keyboard view that we were looking for.
      if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES) {

        // animate the keyboard moving
        CGContextRef context = UIGraphicsGetCurrentContext();
        [UIView beginAnimations:nil context:context];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:0.4];

        // remove the keyboard
        CGRect frame = keyboard.frame;
        // if (keyboard.frame.origin.x >= 0) {
        if (keyboard.frame.origin.y < 480) {
          // slide the keyboard onscreen
          //frame.origin.x = (keyboard.frame.origin.x - 320);

          // slide the keyboard onscreen
          frame.origin.y = (keyboard.frame.origin.y + 264);
          keyboard.frame = frame;
        }
        else {
          // slide the keyboard off to the side
          //frame.origin.x = (keyboard.frame.origin.x + 320);

          // slide the keyboard off
          frame.origin.y = (keyboard.frame.origin.y - 264);
          keyboard.frame = frame;
        }

        [UIView commitAnimations];
      }
    }
  }
}
-(无效)隐藏板
{
用于[[UIApplication sharedApplication]windows]中的(UIWindow*键盘窗口){
//现在迭代可用窗口的每个子视图
用于(UIView*键盘位于[键盘窗口子视图]){
//检查我们引用的视图是否为UIKeyboard。
//如果是这样,那么我们找到了我们正在寻找的键盘视图。

如果([[keyboard description]hasPrefix:@“找到了此问题的答案。但这不是标准答案,正如Dave所说,可能是应用程序审查者的禁忌。使用此页面中的代码作为起点:

我添加了一个动画块。你可以用一个标准外观的动画关闭键盘视图,但不管是什么第一响应者都会保持这种状态。实际上,键盘只是隐藏在屏幕外

- (void)hideKeyboard 
{
  for (UIWindow *keyboardWindow in [[UIApplication sharedApplication] windows]) {

    // Now iterating over each subview of the available windows
    for (UIView *keyboard in [keyboardWindow subviews]) {

      // Check to see if the view we have referenced is UIKeyboard.
      // If so then we found the keyboard view that we were looking for.
      if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES) {

        // animate the keyboard moving
        CGContextRef context = UIGraphicsGetCurrentContext();
        [UIView beginAnimations:nil context:context];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:0.4];

        // remove the keyboard
        CGRect frame = keyboard.frame;
        // if (keyboard.frame.origin.x >= 0) {
        if (keyboard.frame.origin.y < 480) {
          // slide the keyboard onscreen
          //frame.origin.x = (keyboard.frame.origin.x - 320);

          // slide the keyboard onscreen
          frame.origin.y = (keyboard.frame.origin.y + 264);
          keyboard.frame = frame;
        }
        else {
          // slide the keyboard off to the side
          //frame.origin.x = (keyboard.frame.origin.x + 320);

          // slide the keyboard off
          frame.origin.y = (keyboard.frame.origin.y - 264);
          keyboard.frame = frame;
        }

        [UIView commitAnimations];
      }
    }
  }
}
-(无效)隐藏板
{
用于[[UIApplication sharedApplication]windows]中的(UIWindow*键盘窗口){
//现在迭代可用窗口的每个子视图
用于(UIView*键盘位于[键盘窗口子视图]){
//检查我们引用的视图是否为UIKeyboard。
//如果是这样,那么我们找到了我们正在寻找的键盘视图。

如果([[keyboard description]hasPrefix:@]我从来没有说过我不想要一个数据输入系统,只是我想让键盘消失。我想在一个不同于平常的位置创建一个自定义键盘。这就是你正在考虑的数据输入系统。我从来没有说过我不想要一个数据输入系统,只是我想让键盘消失。我想创建一个自定义键盘B板的位置与平常不同。这就是你正在考虑的数据输入系统。