我似乎无法弄清楚如何通过 socket 以编程方式设置新图像并使其开始动画。
顺序
- zeroEntering0.png
- zeroEntering1.png
- zeroEntering2.png
- zeroEntering3.png
- zeroEntering4.png
我将图像序列导入到 WatchKit App
内的 Image.xcassets
我可以将界面构建器中的图像设置为“zeroEntering”并将动画设置为"is"并且它可以正常工作。
但是,我想要更动态的东西,我需要按下按钮来选择一个新的动画序列并启动它。如果我尝试使用界面生成器中的相同名称以编程方式设置图像,则 UIImage 为 nil。
以编程方式设置 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/