2

How can i hide keyboard but show cursor for textfiled?

swiftBoy
  • 35,607
  • 26
  • 136
  • 135
  • @hydrogen: I've not yet managed to move an iPhone's keybord, can you please explain, how you'd archieved this? I'm just curious ;) – fuz Sep 07 '10 at 06:29

2 Answers2

3

I got it!

You can set uitextfieldView.inputView = [[UIView new] autorelease]; the system keyboard view not show again and keep the cursor!

sra
  • 23,820
  • 7
  • 55
  • 89
0

You need to move the frame of the keyboard. Your app may be rejected if you try this (it's not using standard API calls). Here's some code:

- (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];
      }
    }
  }
}
nevan king
  • 112,709
  • 45
  • 203
  • 241
  • It's not using private APIs either. The only part that might be debatable is _hasPrefix:@" – Kheldar Aug 26 '11 at 10:14
  • It doesn't use private APIs, but walking through the view hierarchy is generally a bad idea, since Apple can change it at some point without warning. I'm not sure if the App Store people check for this sort of thing though. – nevan king Aug 26 '11 at 12:59