2015-08-08 54 views
-1

我試圖使用UIImage.animatedImageWithImages方法在手錶屏幕上顯示一個簡單的動畫(有一系列35個狀態的PNG文件)。WatchKit中的圖像動畫無法正常工作

當我運行下面的代碼,我認爲應該工作,只加載一個靜態圖像。這是來自一個小測試項目,在屏幕上只有一個按鈕和一個圖像,點擊按鈕時,下面的方法運行應該加載動畫,但它只加載靜態圖像。

@IBAction func clicked() { 

    var progressImages = [UIImage]() 

    for index in 1...35 { 
     let image = UIImage(named: "r\(index).png") 
     progressImages.append(image!) 
    } 

    image.setImage(UIImage.animatedImageWithImages(progressImages,duration: 3.0)) 

} 

任何想法我在做什麼錯在這裏?

+0

通過嘗試將所有這些圖像同時加載到內存中來使用所有系統內存。在編寫代碼之前對如何實現動畫進行一些研究,SO上有數百個關於如何很好地實現動畫的答案。 – MoDJ

回答

0
(IBAction)playAnimation { 
    // Uses images in WatchKit app bundle. 
    [self.animatedImage setImageNamed:@"Bus"]; 
    [self.animatedImage startAnimating]; 

    // Animate with a specific range, duration, and repeat count. 
    // [self.animatedImage startAnimatingWithImagesInRange:NSMakeRange(0, 4) duration:2.0 repeatCount:3]; 
} 

(IBAction)stopAnimation { 
    [self.animatedImage stopAnimating]; 
}