我試圖對UIButton的縮放進行動畫製作,但難以通過動畫以我想要的方式進行動畫製作。僅從底部垂直縮放UIButton
我有一個UIButton設置了可伸縮的UIImage。我希望它的高度能夠縮放到一定的尺寸,並賦予它「增長」的效果。我使用下面的代碼,但它激活了從頂部和底部增長的UIButton,而不僅僅是底部。看到這裏的代碼:
myButton.transform = CGAffineTransformMakeScale(1,0.5);
myButton.alpha = 0.6f;
[UIView beginAnimations:@"myButton" context:nil];
[UIView setAnimationDuration:0.5];
myButton.transform = CGAffineTransformMakeScale(1,1);
myButton.alpha = 1.0f;
[UIView commitAnimations];
這很難解釋,基本上我想要的UIButton僅從一側(底部),而不是把它擴大雙方成長壯大。有什麼建議麼?
UPDATE
我也試圖改變按鈕的邊框,並且也不能工作。這一次,根本沒有看到動畫。這是我的代碼:
CGRect buttonRect = CGRectMake(0, 0, 150, 22);
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];
myButton.frame = buttonRect;
myButton.alpha = 0.6f;
[self.view addSubview:myButton];
[UIView beginAnimations:@"myButton" context:nil];
[UIView setAnimationDuration:0.3];
CGRect buttonRect2 = CGRectMake(0, 0, 150, 52);
myButton.frame = buttonRect2;
myButton.alpha = 1.0f;
[UIView commitAnimations];
任何想法,爲什麼它根本不是動畫?我假設它與我如何設置框架有關?
感謝賈斯汀,我試過上方(參見下UPDATE編輯問題),現在它不根本沒有動畫。任何建議,我做錯了什麼?再次感謝! – trx25 2010-12-10 12:46:56
所示的更新看起來正確。有沒有其他地方可以修改`myButton`?代碼看起來像用圖像初始化它的地方是什麼? – 2010-12-10 17:07:11