使用 WatchKit 以编程方式设置 UIImage 动画
Programatically Set UIImage Animation with WatchKit
我似乎无法弄清楚如何通过插座以编程方式设置新图像并使其开始动画。
序列
- zeroEntering0.png
- zeroEntering1.png
- zeroEntering2.png
- zeroEntering3.png
- zeroEntering4.png
我把图像序列导入到Image.xcassets里面 WatchKit 应用程序
我可以将界面生成器中的图像设置为 "zeroEntering" 并将动画设置为 "Yes",它可以正常工作。
但是,我想要更有活力的东西,我需要按下按钮来选择新的动画序列并开始播放。如果我尝试使用界面生成器中的相同名称以编程方式设置图像,则 UIImage 为 nil。
以编程方式设置 UIImage 时应该使用什么命名约定? "zeroEntering"、"zeroEntering0"、"zeroEntering.png" 或 "zeroEntering0.png"
我尝试使用两个非零选项,但图像没有动画并且变黑了。
设置图像为[UIImage imageNamed:@"entering"]
然后调用startAnimatingWithImagesInRange:duration:repeatCount:
答案很微妙,肯定让我的轮子转得太久了。
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!
所以,我将我的图片保存在手表应用程序的资产目录中,并切换到使用,
[self.testImage setImageNamed:@"zeroEntering"];
[self.testImage startAnimatingWithImagesInRange:NSMakeRange(0, 4) duration:0.2 repeatCount:100];
我似乎无法弄清楚如何通过插座以编程方式设置新图像并使其开始动画。
序列
- zeroEntering0.png
- zeroEntering1.png
- zeroEntering2.png
- zeroEntering3.png
- zeroEntering4.png
我把图像序列导入到Image.xcassets里面 WatchKit 应用程序
我可以将界面生成器中的图像设置为 "zeroEntering" 并将动画设置为 "Yes",它可以正常工作。
但是,我想要更有活力的东西,我需要按下按钮来选择新的动画序列并开始播放。如果我尝试使用界面生成器中的相同名称以编程方式设置图像,则 UIImage 为 nil。
以编程方式设置 UIImage 时应该使用什么命名约定? "zeroEntering"、"zeroEntering0"、"zeroEntering.png" 或 "zeroEntering0.png"
我尝试使用两个非零选项,但图像没有动画并且变黑了。
设置图像为[UIImage imageNamed:@"entering"]
然后调用startAnimatingWithImagesInRange:duration:repeatCount:
答案很微妙,肯定让我的轮子转得太久了。
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!
所以,我将我的图片保存在手表应用程序的资产目录中,并切换到使用,
[self.testImage setImageNamed:@"zeroEntering"];
[self.testImage startAnimatingWithImagesInRange:NSMakeRange(0, 4) duration:0.2 repeatCount:100];