Fabrizio Bartolomucci Fabrizio Bartolomucci - 1 month ago 36
iOS Question

UIImage.animatedImageNamed returns nil

I am trying to load a sequence of images in an animation. I am keeping those images in the assets (spinner1 to spinner42) and so I am using:

@IBOutlet weak var imageView: WKInterfaceImage!
override func didAppear() {
super.didAppear()
let animatedImage = UIImage.animatedImageNamed("spinner", duration: 10)
imageView.setImage(animatedImage)
}
}


But I am always returned a nil image. If I set spinner1, I se the image but no animation. What is the proper way to animate an image on WatchKit?

Answer

As for also the updated answer from joe the correct code I also used is:

@IBOutlet weak var imageView: WKInterfaceImage!
override func didAppear() {
    super.didAppear()
    imageView.setImageNamed("spinner")
    imageView.startAnimatingWithImages(in:NSRange(location:1, length: 41), duration: 2, repeatCount: 0)
}