2010-02-18 99 views
4

我想在我的應用程序中創建一個「立即購買」按鈕,它應該與App Store中的應用程序的工作方式相同,但我不知道如何用動畫調整UIButton的大小。UIButton立即購買效果

我曾嘗試以下,但調整按鈕一次,而不是作爲一個動畫:

[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:10.5]; 
[buyButton setFrame:CGRectMake(20, 115, 70, 21)]; 
[UIView commitAnimations]; 

凡「buyButton」是一個UIButton。

我查過了這篇文章UIButton AppStore buy button animation,但似乎沒有工作。

+0

你的代碼爲我工作。你意識到10.5秒是非常長的時間?你確定你選擇的框架與按鈕已經不一樣了嗎?確保此代碼在您按下按鈕時執行,而不是在之前執行。還要在該代碼片段中使用NSLog語句,以便您可以檢查日誌並查看它是否在您不知情的情況下執行兩次。看到更多的代碼可能會有所幫助,例如:你的程序中的代碼駐留在哪裏? – Andrew 2010-03-13 10:45:46

回答

1

試試這個:

[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:duration]; 

CGAffineTransform scale = CGAffineTransformMakeScale(scalingFactorX, scalingFactorY); 
buyButton.transform = scale; 

[UIView commitAnimations]; 

使用CGAffineTransform可能會有幫助。我沒有嘗試過,但是,它應該工作。