2015-04-15 21 views
2

WKInterfaceImage的setImageData文檔中提到「數據可以是原始圖像數據或歸檔的UIImage對象......該參數中的數據對象可能包含多個圖像,以便圖像內容可以動畫「。如何將多個圖像加載到WKInterfaceImage

有人能告訴我一個關於如何從多個圖像構建一個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]; 

但這不起作用!

回答

2

而不是使用setImageData只使用setImage並直接傳遞圖像。

self.wkInterfaceImage setImage:img]; 

而且,你會希望你的動畫圖像的持續時間更改爲大於0

+0

我不知道我怎麼錯過了setImage呼叫更大,但它的工程!謝謝! – user2698075

相關問題