2013-02-06 57 views
1

在我的項目中,我必須創建某種特定的動畫。這個想法是,我必須移動兩個UILabel,它們都應該放下,但最初一個在另一個之上。最初我還有一個矩形區域,底部的UILabel位於其中,當動畫開始時,它應該看起來像兩個UILabels都在某個旋轉的輪子上,當它下降時,底部的一個會消失(因爲它無法通過那個矩形窗口看到),頂部的一個取代它。iPhone - 在某個區域的動畫

我試圖通過計時淡入和淡出UILabels來達到這個效果,但是看起來好像很差。我想解決這個問題的唯一方法是爲矩形周圍的區域設置動畫,但只在該區域顯示動畫。你能給我一些關於如何做的建議嗎?

這裏是一個事先知情同意:

Here is a pic:

下面是一些代碼,我一直試圖做來實現這一目標:

[UIView animateWithDuration:0.3 animations:^{ 
encouragementLabel.alpha = 1.0; 
encouragementLabel.center = CGPointMake(encouragementLabel.center.x,encouragementLabel.center.y+40);}]; 

[UIView animateWithDuration:0.3 animations:^{ 
answer.alpha = 0; 
answer.center = CGPointMake(answer.center.x, answer.center.y+40);}]; 

回答

1

嘗試添加標籤爲子視圖矩形視圖。確保矩形視圖的clipsToBounds屬性或layer.masksToBounds設置爲YES,這將隱藏矩形邊界外的所有子視圖。現在,當您爲標籤設置動畫時,它們會在離開矩形後自動隱藏,並在它們移動時出現。

0

您可以簡單地嘗試這個......

[UIView animateWithDuration:0.3 animations:^{ 
     encouragementLabel.alpha = 1.0; 
     encouragementLabel.center = 
      CGPointMake(encouragementLabel.center.x,encouragementLabel.center.y+40); 
} completion:^(BOOL finished) { 
     [UIView animateWithDuration:0.3 animations:^{ 
     answer.alpha = 0; 
     answer.center = CGPointMake(answer.center.x, answer.center.y+40);}]; 
}];