2011-08-15 164 views
0

好的,所以我想製作一個菜單,在當前觸摸位置向下擴展。我通過加入我的menuView爲1的高度,然後改變高度到我所需的一個這樣的實現這一點:按下UIView按鈕

[UIView beginAnimations:NULL context:nil];   
CGRect fullRect; 
fullRect = CGRectMake(menuView.frame.origin.x, menuView.frame.origin.y, 290, 180); 
menuView.frame = fullRect; 
[UIView commitAnimations]; 

現在的問題是,有在該menuView 4個按鈕,並且這些按鈕出現,然後再菜單視圖展開在它們下面。任何想法如何使按鈕出現 menuView而不是之前呢?

回答

0

您必須設置menuView.clipsToBounds = YES,以便在擴展時不會在menuView的邊界外顯示按鈕。

我還將添加以下內容以使按鈕具有淡入效果。

button1.alpha = 0.0; // Do this for each button before the [UIView beginAnimations]; 

button1.alpha = 1.0; // Do this during the animation block. 
+0

真棒,正是我所需要的!非常感謝你! – kopproduction

0

我會使用塊動畫代替。這樣,您可以輕鬆地在動畫過程中或動畫後出現按鈕。嘗試如下:

[UIView animateWithDuration:1.0 
         animations:^{ 
         CGRect newRect = menuView.frame; 
         menuView.size.height += 289; 
         menuView.frame = newRect; 
         } 
         completion:^(BOOL finished){ 

         [UIView animateWithDuration:0.1 
              animations:^{ 
              button.hidden = NO; 
              } 
              completion:^(BOOL finished){ 
              ; 
              }]; 
         }]; 

這將使按鈕停止隱藏在動畫的結尾。當然,您可以在完成塊中添加更多的塊來處理更多的動畫,並且很容易對其進行自定義。希望有所幫助!

+0

隱藏屬性不是動畫。 'alpha'(opacity)是可以動畫的,但是在你設置爲1.0(不透明)之前,你必須確保按鈕的alpha值爲0.0(透明)。否則,它不會動畫。 – Roberto

+0

您會注意到設置button.hidden = NO位於完成塊中,意味着它將在動畫後發生。你是對的,如果你想讓按鈕淡出,你將不得不設置alpha值,但在我的例子中,我只是希望它出現在最後。 – msgambel