【问题标题】:Simple Animations [iPhone]简单动画 [iPhone]
【发布时间】:2009-10-28 00:45:32
【问题描述】:

我有一些 UIButtons,我想在屏幕中间按下时触发 5-10 帧短动画以及其他不相关的东西。我可以在 IB 中放置一个 UIImageView 并以某种方式以编程方式对其进行更新吗?它不需要过于复杂,我什至不介意它是否是硬编码的,因为它是一个如此小的项目。

谢谢。

【问题讨论】:

    标签: iphone animation uiimageview


    【解决方案1】:

    以下是您制作仅几帧动画的最简单方法的示例:

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

    【讨论】:

    • 是的,是的,是的!这绝对正是我所需要的。不太复杂,而且足够简单,易于实施。
    【解决方案2】:

    是的。为您的 UIImageView 创建一个 IBOutlet,您可以从代码中更新它。例如,使用其image 属性来设置应显示的 UIImage。或者,您可以将图像添加到应用程序的资源中,并将其与 Interface Builder 中的 UIImageView 关联。使用 .png 文件,因为 iPhone 已针对它们进行了优化。
    由于 UIImageView 是 UIView,所有常用的 Core Animation methods 都可以使用。

    【讨论】:

      猜你喜欢
      • 2014-02-15
      • 2015-08-26
      • 2012-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多