2013-05-16 65 views
2

我有一組按鈕顯示在UIViewController的中心。爲了給出這樣的效果:按鈕在視圖加載時一個接一個地彈出/出現在視圖中我試圖找出在我的UIViewController加載之後加載UIButtons,或者在彼此的另一個加載之內加載,以便它們快速加載但在視圖加載之後,按鈕的視覺動畫彈出。UIView加載後加載UIButton

有沒有人有這樣做與UIButton的例子?

+2

你在找什麼可能是UIViewController上的「viewWillAppear」方法 – bengoesboom

+2

你總是可以增加alpha。從0.0f開始,以1.0f結束。它會使褪色生效,並將開始隱形。 – ApolloSoftware

回答

2

最初,當視圖控制器接到對viewDidLoad的呼叫時,您想要設置您的按鈕,以使其具有零alpha

然後,在viewDidAppear:您可以配置一組動畫的使用,顯示的按鈕:

[UIView animateWithDuration:<#(NSTimeInterval)#> 
         delay:<#(NSTimeInterval)#> 
        options:<#(UIViewAnimationOptions)#> 
       animations:<#^(void)animations#> 
       completion:<#^(BOOL finished)completion#>] 

使用delay太空,每個按鈕的顯示和animations塊指定按鈕的顯示方式。在動畫塊中,您可以將alpha設置爲1以使按鈕顯示。您也可以在按鈕上添加一個比例尺transform,使其尺寸發生變化(用於彈出效果)。

+0

該解決方案停止使用iOS7。 – motionpotion

2

你可能想是這樣的:

- (void)viewWillA pear:(BOOL)animated { 
    [super viewWillAppear:animated]; 
    _button.alpha = 0; 
    UIView animateWithDuration:1 animations:^{ 
     _button.alpha = 1; 
    }]; 
} 
2

您可以隨時增加阿爾法。從0.0f開始,以1.0f結束。它會使褪色生效,並將開始隱形。

   yourButton.alpha = 0.0f; 
      [yourView addSubview:yourButton]; 

      [UIView animateWithDuration:1.0 
        delay:0.0 
       options: UIViewAnimationCurveEaseInOut 
      animations:^{yourButton.alpha = 1.0;} 
      completion:nil]; 
+1

我使用了所有答案的一部分。謝謝大家的慷慨幫助。 – motionpotion

1

使用以下的NSTimer在viewDidApper方法方法

[的NSTimer scheduledTimerWithTimeInterval:1.0 目標:自 選擇器:@selector(targetMethod :) USERINFO:無 重複:NO];

//寫targetMethod:每1秒後調用一次該方法。編寫代碼將按鈕添加爲子視圖以在該方法中進行屏幕顯示,或者您可以控制按鈕的可見性,然後在targetMethod中使按鈕可見。當所有加載的按鈕完全使用NSTimer的無效方法來停止調用targetMethod時。