2010-12-12 29 views
0

J'essaie de créer une barre de recherche similaire à celle du navigateur Safari sur iPad. Je pense que c'est un UITextview seulement. Au clic du contrôle, sa taille va augmenter. Et quand l'orientation est tournée, elle maintient la taille en conséquence. Comment puis-je y parvenir en utilisant l'option de redimensionnement automatique? Ou dois-je coder manuellement pour l'atteindre?Question iPad simple - Navigateur Safari - Barre de recherche Google

Répondre

1

Vous pouvez faire tout cela directement dans Interface Builder.

Le composant Barre de recherche vous offre les fonctionnalités appropriées. Pour que la barre se redimensionne correctement, il vous suffit de l'ancrer aux côtés appropriés de l'écran et de le rendre extensible. Essayez d'ouvrir this file avec IB pour un exemple.

0
Use the below code to your controller and make sure the you have a textfield delegate. 

- (void)textFieldDidBeginEditing:(UITextField *)textField 
{ 
    UIInterfaceOrientation orientation = self.interfaceOrientation; 
    if (orientation== UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) { 

     if(textField==searchField){ 


      CGRect searchFrame = searchField.frame; 
      searchFrame.size.width += 150; 
      searchFrame.origin.x -= 150; 


      [UIView beginAnimations: @"GrowTextField" context: nil]; 
      { 
       searchField.frame = searchFrame; 
       [UIView setAnimationDuration: 0.5]; 
      } 
      [UIView commitAnimations]; 
     } 


    } 

    else if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) 
    {  
     if(textField==searchField){ 


      CGRect searchFrame = searchField.frame; 
      searchFrame.size.width += 150; 
      searchFrame.origin.x -= 150; 

      [UIView beginAnimations: @"GrowTextField" context: nil]; 
      { 
       searchField.frame = searchFrame; 
       [UIView setAnimationDuration: 0.5]; 
      } 
      [UIView commitAnimations]; 
     } 
    } 

} 



- (void)textFieldDidEndEditing:(UITextField *)textField{ 
    UIInterfaceOrientation orientation = self.interfaceOrientation; 
    if (orientation== UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) { 
     if(textField==searchField){ 

      CGRect searchFrame = searchField.frame; 
      searchFrame.size.width -= 150; 
      searchFrame.origin.x += 150; 


      [UIView beginAnimations: @"ShrinkTextField" context: nil]; 
      { 
       searchField.frame = searchFrame; 
       [UIView setAnimationDuration: 0.5]; 
      } 
      [UIView commitAnimations]; 

     } 


    } 

    else if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) 
    {  

     if(textField==searchField){ 

      CGRect searchFrame = searchField.frame; 
      searchFrame.size.width -= 150; 
      searchFrame.origin.x += 150; 


      [UIView beginAnimations: @"ShrinkTextField" context: nil]; 
      { 
       searchField.frame = searchFrame; 
       [UIView setAnimationDuration: 0.5]; 
      } 
      [UIView commitAnimations]; 

     } 
    } 


}