2010-09-07 7 views
2

Comment puis-je masquer le clavier mais afficher le curseur pour textfiled?Masquer le clavier mais afficher le curseur

+0

@hydrogène: Je n'ai pas encore réussi à déplacer la clé d'un iPhone, pouvez-vous m'expliquer comment vous l'avez fait? Je suis juste curieux;) – fuz

+1

Comment le mettre derrière le bureau? –

Répondre

0

Vous devez déplacer le cadre du clavier. Votre application peut être refusée si vous l'essayez (elle n'utilise pas les appels API standard). Voici un 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

Il n'utilise pas non plus d'API privées. La seule partie qui pourrait être discutable est _hasPrefix: @ " Kheldar

+0

Il n'utilise pas d'API privées, mais parcourir la hiérarchie des vues est généralement une mauvaise idée, car Apple peut le modifier à un moment donné sans avertissement. Je ne suis pas sûr si les gens App Store vérifient pour ce genre de chose cependant. –

3

Je l'ai eu!

Vous pouvez définir uitextfieldView.inputView = [[UIView new] autorelease]; la vue du clavier système ne s'affiche pas à nouveau et garder le curseur!

Questions connexes