通过WatchKit以编程方式设置UIImage动画 [英] Programatically Set UIImage Animation with WatchKit

查看:60
本文介绍了通过WatchKit以编程方式设置UIImage动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法弄清楚如何以编程方式通过插座设置新图像,并使其开始动画制作.

I can't seem to figure out how to programmatically set a new image, via the outlet, and make it start animating.

序列

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

我将图像序列导入 WatchKit App

I imported the sequence of images into the Image.xcassets inside the WatchKit App

我可以在界面生成器中将图像设置为"zeroEntering",并将动画设置为是",这样就可以正常工作.

I can set the image in the interface builder to "zeroEntering" and set animating to "Yes" and it works correctly.

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

However, I want something more dynamic, I need a button press to choose a new animation sequence and start it off. If I try and set the image programmatically using the same name from the interface builder, the UIImage is nil.

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

What naming convention should I use when programmatically setting the UIImage? "zeroEntering", "zeroEntering0", "zeroEntering.png" or "zeroEntering0.png"

我尝试使用两个非nil选项,并且图像没有动画并变黑.

I tried using the two non-nil options and the image did not animate and went black.

推荐答案

答案很微妙,肯定让我的车轮转动了太长时间.

The answer is subtle and definitely got my wheels spinning for too long.

根据此美丽的文章

当要显示的图像缓存在手表上时,您应该使用 setImageNamed(:)在手表应用程序捆绑包中的资产目录中,并使用setImage(:):当不缓存图像时-会将图像数据通过空中传输到Apple Watch!

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应用程序的资产目录中,并切换为使用,

So, I kept my images in the assets catalog on the watch app, and switch to use,

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

这篇关于通过WatchKit以编程方式设置UIImage动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆