2009-10-08 48 views
1

我創建一個UIButton有stretchableImageWithLeftCapWidth:topCapHeight:Cocoa Touch中可拉伸按鈕圖像的大小是否可以動畫?

我想改變它的大小與流暢的Core Animation,像這樣:

float shrinkFactor = 0.2; 
NSTimeInterval slowSpeed = 5.0; 

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

UIButton *thisButton = (UIButton *)[self.view viewWithTag:2]; 
thisButton.frame = CGRectMake(thisButton.frame.origin.x, thisButton.frame.origin.y, buttonStretchedWidth * shrinkFactor, thisButton.frame.size.height); 

[UIView commitAnimations]; 

按鈕圖像尺寸不動畫,它只是捕捉到新的尺寸。

當我使backgroundColor的按鈕可見時,我看到框架本身的動畫正確。

我錯過了什麼東西,或者圖像拉伸不動畫?

回答

2

我從來沒有能夠獲得圖像拉伸不斷更新。嘗試將您的圖片分割成大寫字母和中心區域,然後使用相應的autoresizingMask集創建八個或九個UIImageView子視圖。例如。右上角視圖應該有UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin,底部中心視圖(拉伸)應該有UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin,依此類推。 iPhone OS上的視圖相當便宜,一旦創建,所以我不認爲你會看到性能下降,除非你一次動畫六個按鈕。確保做出任何不透明的東西,儘管 - 合成不透明的視圖非常昂貴。

相關問題