OGeek|极客世界-中国程序员成长平台

标题: ios - 如何将多个图像加载到 WKInterfaceImage [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 15:04
标题: ios - 如何将多个图像加载到 WKInterfaceImage

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];

但这不起作用!



Best Answer-推荐答案


不要使用 setImageData,而是使用 setImage 并直接传递图像。

self.wkInterfaceImage setImage:img];

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

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






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4