2010-12-20 91 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); 

,现在它的工作!

相关问题