2

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

4

2 回答 2

3

我知道了!

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

于 2011-08-26T08:56:22.467 回答
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];
      }
    }
  }
}
于 2010-09-07T10:07:46.470 回答