开发者

Hide keyboard but show cursor [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be 开发者_如何学运维improved and possibly reopened, visit the help center for guidance. Closed 10 years ago.

How can i hide keyboard but show cursor for textfiled?


I got it!

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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜