ios - 如何加载多个图像到WKInterfaceImage

标签 ios watchkit apple-watch

WKInterfaceImage的setImageData文档说“数据可以是原始图像数据,也可以是存档的UIImage对象......这个参数中的数据对象可以包含多个图像,以便可以对图像内容进行动画处理。”

有人可以向我展示一段代码片段,说明如何从多个图像构造 NSData 对象,并将其加载到 WKInterfaceImage 对象中吗?

这是我能解释的最好的方法。

UIImage * img1 = [UIImage imageNamed:@"img1.png"];
UIImage * img2 = [UIImage imageNamed:@"img2.png"];

UIImage * img = [UIImage animatedImageWithImages:@[img1, img2] duration:0];

NSData * data = [NSKeyedArchiver archivedDataWithRootObject:img];


[self.wkInterfaceImage setImageData:data];
[self.wkInterfaceImage startAnimating];

但这不起作用!

最佳答案

不使用 setImageData,只使用 setImage 并直接传递图像。

self.wkInterfaceImage setImage:img];

此外,您还需要将动画图像的持续时间更改为大于 0 的值。

关于ios - 如何加载多个图像到WKInterfaceImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29655302/

相关文章:

ios - UITableView 内容中的空间

ios - 如何将日期字符串从 Rails 转换为 Swift

ios - 以编程方式隐藏和显示 WKInterfaceGroup

swift - Xcode - 仪器 : missing symbols

ios - Apple 表盘 : change from an app running on watch

IOS 无法从 TableView Controller 导航到另一个

objective-c - 在 iOS 应用程序中使用 STL

ios - 如何在 Xcode 中更改 Watchkitapp 和扩展的代码签名权利

ios - WatchKit 为 Label 添加边距

watchkit - 在哪里可以找到 watchOS 2 的 Taptic 反馈 API 文档或功能?