【问题标题】:Restarting animation when I touch a button触摸按钮时重新启动动画
【发布时间】:2010-12-20 12:20:50
【问题描述】:

单击按钮时我需要重新启动动画。

这是我的动画的代码:

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];

问题是:当我重新单击(第二次单击)按钮时,动画不起作用!

你能帮帮我吗?

【问题讨论】:

  • 为什么这个动画第二次不起作用?

标签: iphone cocoa-touch animation uiimageview


【解决方案1】:

我发现了问题。 错误是 imgStar.transform。我尝试使用此代码:

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

而不是

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

现在它工作了!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-14
    • 1970-01-01
    • 2012-07-18
    相关资源
    最近更新 更多