The correct way to cache an animated image on Apple Watch?
I am developing an Apple watch app, Displaying data using WKInterfaceTable, each row has an animated image (80 frames, 10 sec duration)
I want to animate this image every 10 seconds, but there is a problem, this makes the Watch very laggy when the image ends up animating and starts animating again.
I tried removing the animation to check if the lag issue is causing the issue and the result is YES.
I was looking for solutions to cache image on Apple Watch, I made the following code:
First, lazy loading image from iPhone, create an animated UIImage
- (UIImage *)countDownImage
{
if (_countDownImage == nil) {
NSMutableArray *array = [[NSMutableArray alloc] init];
for (int i=0; i<=79; i++) {
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"counteight-%i", i]];
[array addObject:image];
}
_countDownImage = [UIImage animatedImageWithImages:array duration:10.0f];
}
return _countDownImage;
}
Second, in my WKInterfaceController which contains the WKInterfaceTable
Add cached image to cache using WKInterfaceDevice
if ([[WKInterfaceDevice currentDevice].cachedImages objectForKey:@"countImage"] == nil) {
[[WKInterfaceDevice currentDevice] addCachedImage:self.countDownImage name:@"countImage"];
}
Finally, in my RowController, use WKInterfaceImage setImageNamed to set the image that I previously cached
[self.animateImage setImageNamed:@"countImage"];
[self.animateImage startAnimatingWithImagesInRange:NSMakeRange(0, 79) duration:10 repeatCount:0];
It works and the image has been cached (Checked:
[[WKInterfaceDevice currentDevice].cachedImages objectForKey:@"countImage"]
)
But it still lags very far behind the real Apple Watch device, even the lagger, than the image in the cache is not configured.
I don't know where I am going wrong, can someone give me some advice on how to cache the animated image on the Apple Watch correctly ?
Thank!
source to share
No one has answered this question yet
Check out similar questions: