隐藏键盘但显示光标

时间:2010-09-07 05:55:28

标签: iphone iphone-softkeyboard

如何隐藏键盘但显示文本字段的光标?

2 个答案:

答案 0 :(得分:3)

我明白了!

您可以设置uitextfieldView.inputView = [[UIView new] autorelease]; 系统键盘视图不再显示并保持光标!

答案 1 :(得分:0)

您需要移动键盘的框架。如果您尝试此操作(可能不使用标准API调用),您的应用可能会被拒绝。这是一些代码:

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