2010-12-20 88 views
0

當我點擊一個按鈕時,我需要重新啓動我的動畫。當我點擊一個按鈕時,重新啓動動畫

這是我的動畫的代碼:

imgStar.frame = CGRectMake(205, 6, imgStar.frame.size.width, imgStar.frame.size.height);  
[UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:1.5]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)]; 
    imgStar.transform = CGAffineTransformMakeTranslation(-4, 340); 
    [UIView commitAnimations]; 

的問題是:當我再次點擊(點擊第二次)我的按鈕動畫不能正常工作!

你能幫助我嗎?

+0

爲什麼這個動畫第二次不起作用? – Dany 2010-12-20 13:25:48

回答

0

我發現了這個問題。 錯誤是imgStar.transform。我嘗試使用此代碼:的

[imgStar setFrame:CGRectOffset([imgStar frame], -4, 340)]; 

代替

imgStar.transform = CGAffineTransformMakeTranslation(-4, 340); 

,現在它的工作!

相關問題