简单动画 [iPhone]

3
我有几个UIButtons,我希望在屏幕中间按下时触发短暂的5-10帧动画,以及其他无关的东西。我能不能只在IB中放一个UIImageView并通过编程方式更新它呢?它不需要过于复杂,现在即使是硬编码也没关系,因为这是一个很小的项目。
谢谢。
2个回答

3
这里是一个关于如何使用几个帧来进行动画的最简单方式的示例:
声明一个 IBOutlet UIImageView *timerAnimation 并将其链接到IB中的UIImageView。将一些图像添加到您的资源中,例如下面所需的内容。然后将这些图像加载到数组中 - 请参见以下代码:
timerAnimation.animationImages = [NSArray arrayWithObjects:
      [UIImage imageNamed:@"timer00.png"],
      [UIImage imageNamed:@"timer01.png"],
      [UIImage imageNamed:@"timer02.png"],
      [UIImage imageNamed:@"timer03.png"],
      [UIImage imageNamed:@"timer04.png"],
      [UIImage imageNamed:@"timer05.png"],
      [UIImage imageNamed:@"timer06.png"],
      [UIImage imageNamed:@"timer07.png"],
      [UIImage imageNamed:@"timer08.png"],
      [UIImage imageNamed:@"timer09.png"],
      [UIImage imageNamed:@"timer10.png"],
      [UIImage imageNamed:@"timer11.png"],
      [UIImage imageNamed:@"timer12.png"],
      [UIImage imageNamed:@"timer13.png"],
      [UIImage imageNamed:@"timer14.png"],
      [UIImage imageNamed:@"timer15.png"],
      [UIImage imageNamed:@"timer16.png"],
      [UIImage imageNamed:@"timer17.png"],
      [UIImage imageNamed:@"timer18.png"],
      [UIImage imageNamed:@"timer19.png"],
      [UIImage imageNamed:@"timer20.png"],
      [UIImage imageNamed:@"timer21.png"],
      [UIImage imageNamed:@"timer22.png"],
      [UIImage imageNamed:@"timer23.png"],
      [UIImage imageNamed:@"timer24.png"],
      [UIImage imageNamed:@"timer25.png"],
      [UIImage imageNamed:@"timer26.png"],
      [UIImage imageNamed:@"timer27.png"],
      [UIImage imageNamed:@"timer28.png"],
      [UIImage imageNamed:@"timer29.png"],
      [UIImage imageNamed:@"timer30.png"],
      [UIImage imageNamed:@"timer31.png"],
      [UIImage imageNamed:@"timer32.png"],
      [UIImage imageNamed:@"timer33.png"],
      [UIImage imageNamed:@"timer34.png"],
      [UIImage imageNamed:@"timer35.png"],
  //      [UIImage imageNamed:@"timer36.png"], save last picture for "times up"
      nil];
timerAnimation.animationDuration = 5.0;
timerAnimation.animationRepeatCount = 1;
[timerAnimation startAnimating];

这将运行您的动画,直至您调用[timerAnimation stopAnimating];


是的,是的,是的,是的!这绝对是我所需要的。不过度复杂,恰到好处,易于实现。 - nullArray

0

可以。创建一个IBOutlet到您的UIImageView,您就可以从代码中更新它了。例如,使用它的image属性来设置应该显示的UIImage。或者,您可以将图像添加到您的应用程序资源中,并在界面构建器中将其与UIImageView关联起来。使用.png文件,因为iPhone已经对它们进行了优化。
由于UIImageView是UIView,所以可以使用所有通常的核心动画方法


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接