I'm late to the party, but I will send my decision because the original plus answer sent by @David did not work for me. I am building on Xcode 8.3.3, compiling for 10.10.
What did not work for me was to create a layer separately and then set it with it.
it did not work for me
CALayer *layer = [CALayer layer]; layer.frame = self.imageView.bounds; layer.bounds = self.imageView.bounds; [self.imageView setLayer:layer];
As a result, there was always no animation.
Apparently 10.10 when you do this:
self.imageView.wantsLayer = YES;
MacOS creates a layer and assigns it to the image view.
So, the code that worked for me was:
self.imageView.wantsLayer = YES; CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"contents"]; [animation setCalculationMode:kCAAnimationDiscrete]; [animation setDuration:1.3f]; [animation setRepeatCount:HUGE_VALF]; [animation setValues:imageArray]; [self.imageView.layer addAnimation:animation forKey:@"contents"]; [self.imageView setAnimates:YES]; [self.imageView setCanDrawSubviewsIntoLayer:YES];
This last line is very important. If you delete this, it will not show any image!
source share