ios - 使用 WatchKit 以编程方式设置 UIImage 动画

标签 ios objective-c animation watchkit

我似乎无法弄清楚如何通过 socket 以编程方式设置新图像并使其开始动画。

顺序

  • zeroEntering0.png
  • zeroEntering1.png
  • zeroEntering2.png
  • zeroEntering3.png
  • zeroEntering4.png

我将图像序列导入到 WatchKit App

内的 Image.xcassets

enter image description here

我可以将界面构建器中的图像设置为“zeroEntering”并将动画设置为"is"并且它可以正常工作。

enter image description here

但是,我想要更动态的东西,我需要按下按钮来选择一个新的动画序列并启动它。如果我尝试使用界面生成器中的相同名称以编程方式设置图像,则 UIImage 为 nil。

enter image description here

以编程方式设置 UIImage 时,我应该使用什么命名约定? “zeroEntering”、“zeroEntering0”、“zeroEntering.png”或“zeroEntering0.png”

我尝试使用两个非零选项,但图像没有动画并且变黑了。

最佳答案

答案很微妙,肯定让我的车轮旋转太久了。

根据这个beautiful article ,

You should use setImageNamed(:) when the image you want to display is either cached on the watch on is in an asset catalog in the watch app’s bundle, and use setImage(:) when the image isn’t cached — this will transfer the image data to the Apple Watch over the air!

所以,我将我的图像保存在 watch 应用程序的 Assets 目录中,并切换到使用,

[self.testImage setImageNamed:@"zeroEntering"];
[self.testImage startAnimatingWithImagesInRange:NSMakeRange(0, 4) duration:0.2 repeatCount:100];

关于ios - 使用 WatchKit 以编程方式设置 UIImage 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29681267/

相关文章:

ios - 将数据从单元格加载到 detailView 始终显示最后的数据

ios - 基于另一个属性的地幔属性类?

javascript - 如何添加动态数量的动画,然后并行运行 Greensock

ios - LocalAuthentication 框架 - 如何让 "Enter Password"在第一次调用时显示

ios - 闹钟中断后 AudioUnitInitialize 失败,错误代码 1701737535 'ent?'

ios - 上传到 iTunes Store 时发生错误

iphone - UIScrollView 每次访问 View 都会更改滚动位置

c# - 如何检查动画师的某个动画状态是否正在运行?

javascript - 类似 Reactjs 的动画库?

ios - 使用来自第二个目标的类