2010-12-12 14 views
0

Ich versuche, eine Suchleiste ähnlich der im Safari-Browser auf dem iPad zu erstellen. Ich denke, es ist nur ein UITextview. Wenn Sie auf das Steuerelement klicken, wird seine Größe erweitert. Und wenn die Ausrichtung gedreht wird, behält sie die Größe entsprechend bei. Wie erreiche ich das mit der automatischen Größenanpassung? Oder muss ich manuell codieren, um es zu erreichen?Einfache iPad Frage - Safari Browser - Google Suchleiste

Antwort

1

Sie können dies alles direkt im Interface Builder tun.

Die Suchleistenkomponente bietet Ihnen die entsprechende Funktionalität. Um die Größe der Leiste zu ändern, müssen Sie sie nur an den entsprechenden Seiten des Bildschirms verankern und dehnbar machen. Versuchen Sie, this file mit IB für ein Beispiel zu öffnen.

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

     } 
    } 


}