2013-03-09 66 views
0

我想動畫化UISearchbar的框架更改。我希望它在點擊搜索按鈕時展開和摺疊。如何動畫UISearchbar框架更改保持圓形的帽子?

正在使用UIViewAnimationBlock動畫

[UIView animateWithDuration:0.5 
           delay:0 
          options:UIViewAnimationOptionLayoutSubviews 
         animations:^{ 
          //Set the frame you want to the search bar 
         } 
         completion:^(BOOL finished) { 

         }]; 

我不得不從零擴大框架和摺疊回來。但是,當動畫時,搜索欄會丟失其圓角並變成矩形。這是它的截圖,同時仍然具有動畫效果enter image description here

它看起來不太好..我希望它在展開或摺疊時保持其圓邊。可能嗎 ?如果是的話如何?

任何幫助將不勝感激。

回答

2

您無法更改高度爲44px的UISearchBar嘗試設置框架的高度。

如果你想改變高度,然後使用CGAffineTransformMakeScale如..

//FOR EXPAND USE THIS: 

[UIView animateWithDuration:0.5 
           delay:0 
          options:UIViewAnimationOptionLayoutSubviews 
         animations:^{ 
          self.searchBar.transform = CGAffineTransformMakeScale(1.0, 1.0); 
         } 
         completion:^(BOOL finished) { 

         }]; 

// FOR展開使用此:

[UIView animateWithDuration:0.5 
           delay:0 
          options:UIViewAnimationOptionLayoutSubviews 
         animations:^{ 
          self.searchBar.transform = CGAffineTransformMakeScale(0.001, 0.001); 
         } 
         completion:^(BOOL finished) { 

         }];